Script to set screen resolution by providing X and Y co-ordinates in RedHat
0
votes
0
answers
321
views
The goal is to provide resolution X and Y as arguments to the script
This is the output of
./res_set.sh 1920 1080
and gtf
, xrandr --newmode
and --addmode
will be executed according to the script.
#!/usr/bin/env bash
if [ "$1" == "-h" ]; then
echo "Usage: basename $0
[X co-ordinate] [Y co-ordinate]"
exit 0
fi
echo "X Co-ordinate";
echo $1;
echo "Y Co-ordinate";
echo $2;
echo "Are you sure? [Y/N]";
read input;
if [ $input == "y" ];
then
gtf $1 $2 60 > kar1.txt #To get modeline
sed -n '3 p' kar1.txt > kar2.txt #Select Line 2
grep -o -E '["_x.0-9 ]+' kar2.txt > kar3.txt #Filter result
wo_filter=$(perl -p -e 's/(?:_60.00)//g' kar3.txt | grep "\S");
filter=$(grep "\S" kar3.txt);
fil_resolution=$(grep -o -P '(?<=").*(?=")' <<< $wo_filter)
resolution=$(grep -o -P '(?<=").*(?=")' kar3.txt)
echo "Filter: $filter";
echo "Wo_filter: $wo_filter";
echo "Resolution: $resolution";
echo "Filted_Resolution: $fil_resolution";
var=$(xrandr --newmode $wo_filter)
xrandr --addmode default $fil_resolution
#rm -v kar*
else
exit;
fi
This creates xrandr --newmode
but fails to add the mode --addmode
in the resolution list while using this script. I get xrandr:Cannot find mode
.
But it works and adds to the mode list if xrandr --newmode
and --addmode
commands are executed individually.



xrandr | tail
My thoughts are :
Are *$variables* are in different datatype and spoiling my result? How will I be able to verify the data type of variables here or in bash (does it matter)?
Asked by Pai
(101 rep)
Feb 9, 2022, 09:37 AM
Last activity: Feb 18, 2022, 04:49 AM
Last activity: Feb 18, 2022, 04:49 AM