command does not work


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting command does not work
# 1  
Old 05-31-2011
command does not work

need help, trying make a command where the user presses any keys and it will go to the home page, however it doesnt work, why ?
Code:
echo -p "press any key to return to main menu" menu
if [[ $menu -gt 1 ]]; then
echo -p "\n"
home
fi


Last edited by Franklin52; 06-01-2011 at 04:55 AM.. Reason: Please use code tags
# 2  
Old 05-31-2011
Need more info

What system and shell are you using? What error are you getting?
# 3  
Old 05-31-2011
im using unix and the error is that it wont execute it so it just shows the text "press any key to return to main menu" and finishes like that.
# 4  
Old 05-31-2011
try this

It's working as expected. The way it is, there is no variable $menu so the test fails.
Try this:
Code:
echo -p "press any key to return to main menu"
read menu
if [[ $menu -gt 1 ]]; then
echo -p "\n"
home
fi


Last edited by gary_w; 05-31-2011 at 02:20 PM..
# 5  
Old 05-31-2011
Quote:
Originally Posted by gary_w
It's working as expected. The way it is, there is no variable $menu so the test fails.
Try this:
Code:
echo -p "press any key to return to main menu"
read menu
if [[ $menu -gt 1 ]]; then
echo -p "\n"
home
fi

That will blow up when the user just hits enter because menu will be a blank string, evaluating to [[ -gt 1 ]], which is a syntax error.

Try if [[ "$menu" -gt 1 ]]; then
# 6  
Old 05-31-2011
Good eye!

I was focusing on the read command and not the rest. Thanks.

---------- Post updated at 02:04 PM ---------- Previous update was at 01:46 PM ----------

Actually, in the korn shell, the double brackets mean use the shell built-in test and it handles the variable being null, thus the code would not error, it would continue after the end of the if statement. Case in point:
Code:
#!/bin/ksh

unset qwaszx

if [[ $qwaszx > 1 ]]; then
  print in here
else
  print here instead
fi

Output:
Code:
 $ ./aa
here instead
$

Nonetheless, for clarity and possible portability to other shells I would still quote the variable inside the test as a matter of good practice.

Image

Last edited by gary_w; 05-31-2011 at 07:00 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy command does not work

I am new to this forum. I have a script which randomly throws error.Following are steps followed in this script: Generate Term file Remove previous term and rpt files from utility directory. copy term file to utility directory call sql to generate rpt file using term file as input copy the... (4 Replies)
Discussion started by: ann15
4 Replies

2. UNIX for Dummies Questions & Answers

sed command does not work as expected

Why when I use this command do I get "E123"? echo NCE123 | sed -n 's/\(.*\)\(\{1,\}\{1,5\}\)\(.*\)/\2/p' But when I used this command, I get NCE123? echo NCE123 | sed -n 's/\(.*\)\(\{3\}\{1,5\}\)\(.*\)/\2/p' I thought \{1,\} would mean any number of characters and \{1,5\ would mean 1-5... (1 Reply)
Discussion started by: newbie2010
1 Replies

3. Shell Programming and Scripting

Would pipe work better with this command

Hi again, have a script that I would like run, but before I can run it I need to strip out the windows \r end of lines. I have put the command into a text file and set the command to run every 10 seconds the coomand I use to do this is while sleep 10; do... (15 Replies)
Discussion started by: Paul Walker
15 Replies

4. UNIX for Dummies Questions & Answers

grep command does not work

Hello. I have a question as to why my grep command does not seem to be working. grep -c '^?*' ~ grep -c '^.*' ~ I wanted to count the number of files starting with the letter K and have some letters after that. I have such files in my home directory. However, the output is 0. So, I have no... (2 Replies)
Discussion started by: FUTURE_EINSTEIN
2 Replies

5. Shell Programming and Scripting

SCP command through ITIM does not work

Hi, We have two Linux box (Machine A and Machine B). Standalone application(ITIM) running on Machine A. Target file to copy is available on Machine B. SSH Handshaking done between Machine A and Machine B using normal user "ssh". Standalone application running on Machine A under user... (2 Replies)
Discussion started by: satish_gauns
2 Replies

6. UNIX for Dummies Questions & Answers

Help with basic command that will not work

I need to be able to look up a file system with the inode number 214743 and, get its absolute reference in a single line... I have tried.. "find / -inum 214743 -print" (1 Reply)
Discussion started by: blankets3
1 Replies

7. UNIX for Dummies Questions & Answers

at command does not work

at command does not work with graphic programs like firefox, evolution, etc It works with other commands for example: at now shutdown -h now OK but at now firefox does not work Anyone knows if its possible to open a firefox window at a scheduled time? Thanks Jose (0 Replies)
Discussion started by: otilesoj
0 Replies

8. UNIX for Dummies Questions & Answers

Command work but not in SH script

Command works but not in SH At terminal if i type: scp test.tar.gz user1@server2:/home/user Everything run smoothly (keyed, no password need) At script , test.sh #!/bin/sh scp test.tar.gz user1@server2:/home/user Nothing happen and clue ? ? ? ? ? (3 Replies)
Discussion started by: cititester
3 Replies

9. HP-UX

ls command doesnt work

Good Day I mistakely renamed the dld.sl file in the /usr/lib directory. When i try to ls/ftp into the box i get this error :eek: crt0: ERROR couldn't open /usr/lib/dld.sl errno:000000002 I have tried to rename it back from the renamed file to the original file name, but it gives me the... (2 Replies)
Discussion started by: shawnbishop
2 Replies

10. AIX

does find command always work ?!

hello ! can so help me ? here is my problem : a same command, using find command works on a server, but doesn't on another. I've been told, that it could be because of the file systems ... it's amazing ! can so explain, please ? thank you for your answer (1 Reply)
Discussion started by: chocolate
1 Replies
Login or Register to Ask a Question