1752577 Members
4111 Online
108788 Solutions
New Discussion юеВ

command $

 
Jairo Campana
Trusted Contributor

command $


hello, example I have $list=`ls`
echo $list
hme0 hme1

I need the ouput
echo $list
hme0
hme1
since I do this
thanks
legionx
7 REPLIES 7
Geoff Wild
Honored Contributor

Re: command $

Why not just do something like:

for i in `ls`
do
echo $i
done

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Jairo Campana
Trusted Contributor

Re: command $

if but I do not want to use for
legionx
harry d brown jr
Honored Contributor

Re: command $

echo $list | tr -s " " "\n"|xargs -i echo {}

live free or die
harry d brown jr
Live Free or Die
Geoff Wild
Honored Contributor

Re: command $

Okay - how about an array:

set -A list `ls`

echo ${list[0]}
echo ${list[1]}

etc

rGds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Biswajit Tripathy
Honored Contributor

Re: command $

I don't get it. Instead of running the following script
--
$list=`ls`
echo $list
--

why not just run

# ls -1

??

- Biswajit
:-)
Geoff Wild
Honored Contributor

Re: command $

Wow - Biswajit - that's sweet!

from man:

-1 (one) List the file names in single column format regardless
of the output device. This forces single column format to
the user's terminal.


Rgds....Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Rodney Hills
Honored Contributor

Re: command $

Since you are not explaining why you are doing what you are doing, then I'm assuming you only want to display all the entries in "$list" on at a time- Try...

echo $list | xargs -n1

Hope that is what you are looking for...

-- Rod Hills
There be dragons...