ls command output to variable and read the variable

Posted: January 14, 2016 in UNIX

Output of a command to a variable:-

myval=`ls $Source_File_Dir -p -1 | grep -v /`

Output of the command ls $Source_File_Dir -p -1 | grep -v
Apple.txt  Orange.txt  cherry.txt fig.txt

myval =Apple.txt  Orange.txt  cherry.txt fig.txt

How to read the variable and process one file at a time

for i in $myval
do
echo $i
done
Output:-
Apple.txt
Orange.txt
fig.txt

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s