Getting User Input in a Shell Script
June 29th, 2009 by Mitch Frazier in
__________________________
Mitch Frazier is an Associate Editor for Linux Journal and the Web Editor for linuxjournal.com.
Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer
Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.
Subscribe now!
The Latest
Newsletter
Tech Tip Videos
- Nov-04-09
- Oct-29-09
- Oct-26-09
Recently Popular
From the Magazine
December 2009, #188
If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.
Delicious
Digg
StumbleUpon
Reddit
Facebook








RE: echo $?
On July 1st, 2009 Chanan (not verified) says:
The $? variable is the exit status of the last command. $1 is the first command line argument passed to the script.
For example, make a script like the following (give it some name I used test.sh):
#!/bin/bash
echo $1
exit 23
Make it executable: chmod 755 test.sh
Then run it with an argument, for example: ./test.sh "Hello"
Then after that run: echo $?
You'll see that "echo $1" in the script returned the argument you passed, while "echo $?" returned the number after "exit" in the script (the exit status).
I used an exit status other then 0 (true) or 1 (false) to hopefully make the example clearer.
Oops, meant to put it as a
On July 1st, 2009 Chanan (not verified) says:
Oops, meant to put it as a reply to Arup's question.
echo $?
On June 30th, 2009 Arup (not verified) says:
Good tip Thanks,
but how does the ? in echo$? work
IS it like $1 ?
Zenity
On June 29th, 2009 Anonymous (not verified) says:
I also use Zenity for most of my shell scripts, being on gnome I guess thats my alternative to kdialog.
Post new comment