Sponsored Content
Full Discussion: How to use for and if?
Top Forums Shell Programming and Scripting How to use for and if? Post 302998753 by Don Cragun on Tuesday 6th of June 2017 09:13:02 PM
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:
 
All times are GMT -4. The time now is 08:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy