How to use for and if?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use for and if?
# 8  
Old 06-06-2017
From what you have said, presumably /home/$chat expands to the home directory for the user named by the expansion of $chat (/home/ram, /home/suresh, and /home/John, respectively for the three lines in /tmp/123.txt).

Therefore, you should get diagnostics from the Korn shell similar to:
Code:
-ksh: /home/ram: cannot execute [Is a directory]
-ksh: /home/suresh: cannot execute [Is a directory]
-ksh: /home/John: cannot execute [Is a directory]

while setting the variable call to an empty string. Directories are not regular files. (Therefore, executing a directory does not work.) They are not text files. (Therefore, greping a directory probably won't give you anything useful.) Filenames (including directories) on UNIX and UNIX-like systems are case-sensitive. User login names on UNIX and UNIX-like systems are almost always entirely lower-case. John might actually be a login name on your system, but it is highly suspicious.

Having done that, the 1st if would always fail and the 2nd if would not be executed, but that doesn't matter because the 2nd if doesn't have a then. So before even starting the for loop, you would have gotten a diagnostic similar to:
Code:
-ksh: syntax error: `else' unexpected

and your script would terminate with a non-zero exit code.

Diagnostics and non-zero exit codes do not qualify as "no o/p from the script".

What is the name of your script?

What output do you get from the command:
Code:
ls -l name

where name is the name of your script?

Exactly what command did you use to invoke your script?
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 06-07-2017
You've fallen into the same trap as in your other thread. Don Cragun pointed the syntax error out (amongst others). The logical one is making the -z test, inverting the desired behaviour.
Plus, on the second sight, you seem to want to evaluate some variables numerically, so -z or -n wouldn't be the correct test.
This User Gave Thanks to RudiC For This Post:
# 10  
Old 06-08-2017
Thanks guys, its worked for me.... both "for" and "while" worked for me, its my bad early i used it wrong.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question