Wednesday 14 November 2012

Get a file from a directory and assign it to variable

 At the bash shell prompt of Linux:

var=$(ls /home/user)

echo $var

this should echo the content of var, which is the listing of /home/user

You may want to assign to a variable the result of a find command:

var2=$(find /home/user -type f -name "MyFile*")

echo $var2

this should list the content of var2 - all files with name starting with "MyFile" in the /home/user path.

No comments:

Post a Comment