LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Help in creating an .sh script (https://www.linuxquestions.org/questions/programming-9/help-in-creating-an-sh-script-558989/)

wild_oscar 06-04-2007 04:36 AM

Help in creating an .sh script
 
I would like some help changing a script I have for my asus, to switch the display between LCD/VGA.

Basically, what I have in the file is:

Code:

echo `echo $1 | sed 's/.*0*6\(.\).*/\1/'` >/proc/acpi/asus/disp
I need some help "translating" this code. What it basically does is changing the value in the .../disp file. What I've failed to understand is how does it determine the $1 value.

Can anyone help me?

What I need is to change the script to:

if (value in file == 1), change to 3
if (value in file == 3), change to 1 and change to 1 again (there's a bug in the acpi4asus and it only works if the value is changed to 1 two times...go figure.

How can I do this?

jschiwal 06-04-2007 04:47 AM

$1 is the first argument to the script or function. It takes a pattern like something0006Nsomething and extracts the N part. So only one character is output and echoed to /proc/aspci/asus/disp.

MS3FGX 06-04-2007 04:49 AM

The "$1" is the first argument given to the script. So if you called the script as:

Code:

bash$ ./myscript.sh test
The $1 variable would be "test".

If you want to make some logical decisions based on that input, you could do something like:

Quote:

case "$1" in
vga)
echo "3" >/proc/acpi/asus/disp
;;
lcd)
echo "1" >/proc/acpi/asus/disp
echo "1" >/proc/acpi/asus/disp
;;
*)
echo $"Usage: $0 {vga|lcd}"
exit 1
esac
I don't know which numbers correspond to which modes, so adjust that accordingly.

But in your post you mentioned a file. Do you want to read the value from a known file rather than using the arguments to the script?

By the way, this would probably be better off in Programming, for future reference.

wild_oscar 06-04-2007 04:55 AM

Quote:

Originally Posted by MS3FGX
I don't know which numbers correspond to which modes, so adjust that accordingly.

But in your post you mentioned a file. Do you want to read the value from a known file rather than using the arguments to the script?

By the way, this would probably be better off in Programming, for future reference.

Basically, I want it to read the value from the /proc/acpi/asus/disp itself.

I've found that the $1 comes from:

Code:


       
Code:

       
vent=hotkey ATKD 0000006[123]
action=~/.asus_acpi/actions/disp-switch.sh '%e'



Where does the '%e' come from?

wild_oscar 06-04-2007 04:59 AM

Quote:

Originally Posted by MS3FGX
The "$1" is the first argument given to the script. So if you called the script as:

Code:

bash$ ./myscript.sh test
The $1 variable would be "test".

If you want to make some logical decisions based on that input, you could do something like:



I don't know which numbers correspond to which modes, so adjust that accordingly.

But in your post you mentioned a file. Do you want to read the value from a known file rather than using the arguments to the script?

By the way, this would probably be better off in Programming, for future reference.


Because the decision should be made automatically by the script (I just want to press the button in my laptop), the script should be something along the lines of

var x = read the value in the file /proc/acpi/asus/disp

if (x == 1)
echo 3 > /proc/.../disp
else
echo 1 > .../disp
echo 1 > .../disp

reddazz 06-04-2007 06:17 AM

Moved: This thread is more suitable in the Programming forum and has been moved accordingly to help your thread/question get the exposure it deserves.


All times are GMT -5. The time now is 04:07 PM.