i am new to shell scripting. My objective is to execute the ls command through a shell script but it does not return anything. Mine is a BASH shell
set p = `/bin/ls`
echo $p
Where am i going wrong
A simple
p=`/bin/ls`
will suffice although I prefer the $() construct since it's easily nestable:
pax$ p=$(/bin/ls)
pax$ echo $p
clients.dat clientupdate.sh
What your set does (after processing all the valid switches to set shell attributes, of which there are none) is to assign the parameters to the $n arguments:
pax$ set p = `/bin/ls`
pax $ echo xx $1 xx $2 xx $3 xx $4 xx $5
xx p xx = xx clients.dat xx clientupdate.sh xx xx
From the man bash_builtins page:
Any arguments remaining after the options are processed are treated as values for the positional parameters and are assigned, in order, to
$1, $2, ... $n.