|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
[bash] Check if variable is set or blank
Hello guys. In my script, i have the following code: Code:
echo "The tarfile contains these directorys"
tar -tf file.tar > tarlist.txt
cat tarlist | awk -F/ '{print $1 "/" $2}' | nl
echo "Enter path of the directory you want to extract or just press enter to extract everything: "
read path
/usr/local/bin/gtar -xf file.tar $pathI need to check if the user gave a path to the script, or if he just pressed enter? I know what to do between the 'THEN' and 'ELSE' statements. I just need to know how to check if $path is really set or not. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Code:
case $path in '') echo not set;; *) echo is set;; esac If you want to distinguish between not set and set but empty, have a look at the ${var-value} and ${var:-value} construct. As long as you are not quoting $path, you don't need to make things conditional, though.. Your code should work already. (On the other hand, you properly ought to put $path in double quotes.) PS. You are extracting into tarlist.txt, but using tarlist without the .txt. Also the cat | awk is a Useless Use of Cat. Google for that phrase. Last edited by era; 03-28-2008 at 09:44 AM.. Reason: P.S. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| check if return value is blank | Satyak | Shell Programming and Scripting | 1 | 12-26-2009 06:24 AM |
| Bash : Check aphanumeric content in variable | ionral | Shell Programming and Scripting | 3 | 11-24-2009 05:41 AM |
| how to check the variable values is blank | julirani | Shell Programming and Scripting | 2 | 12-06-2008 04:24 PM |
| How to check if two variable are empty strings at once? (bash) | ph0enix | Shell Programming and Scripting | 4 | 10-24-2008 02:18 PM |
| check for the first character to be blank | anthreedhr | UNIX for Dummies Questions & Answers | 7 | 10-22-2003 10:05 AM |
|
|