LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-04-2007, 04:36 AM   #1
wild_oscar
Member
 
Registered: Jan 2007
Distribution: OpenSuse 10.2
Posts: 56

Rep: Reputation: 15
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?
 
Old 06-04-2007, 04:47 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
$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.
 
Old 06-04-2007, 04:49 AM   #3
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
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.
 
Old 06-04-2007, 04:55 AM   #4
wild_oscar
Member
 
Registered: Jan 2007
Distribution: OpenSuse 10.2
Posts: 56

Original Poster
Rep: Reputation: 15
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?
 
Old 06-04-2007, 04:59 AM   #5
wild_oscar
Member
 
Registered: Jan 2007
Distribution: OpenSuse 10.2
Posts: 56

Original Poster
Rep: Reputation: 15
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
 
Old 06-04-2007, 06:17 AM   #6
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help creating a script... minm Linux - Newbie 5 01-09-2005 12:27 AM
Creating a script thomas289 Linux - Networking 1 12-17-2004 11:59 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
Help creating a Bash script gothicreader Linux - Newbie 4 10-10-2003 01:36 PM
Creating a Script? BajaNick Linux - Software 1 07-26-2003 07:55 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration