0

I am a pythoneer, guess List is called hash in shell script , I want to know how to do this

for arg in "$@";
do
echo `pwd`'/'$arg;
done

how do i pass the collected this list of items in $args to a different applications that takes these items as list.

4
Contributors
3
Replies
18
Views
4 Years
Discussion Span
Last Post by L7Sqr
0
for arg in "$@"
do
  echo `pwd /${arg}`
done

Although I do not know why you are including a leading slant there, or, actually, ANY argument to pwd. Or are you intending to pass an OPTION to pwd, in which case it should "-" and not "/". "/" is the windows form for options.

0

hi krystosan,

what if you start from the beginning?

what list are talking about?
does the <command> take a list of arguments, or does it take only one argument, and so have to be executed many times?
and so on.

0

The idiomatic way to do this through pipes. As an example, consider the two following scripts:

a.sh

for arg in $@; do
   echo `pwd`/${arg}
done

b.sh

while read line; do
   echo "New entry: ${line}"
done

If the output of a.sh was:

/tmp/foo/1
/tmp/foo/2
/tmp/foo/3

and you piped that to b.sh (i.e. a.sh | b.sh) you would get

New entry: /tmp/foo/1
New entry: /tmp/foo/2
New entry: /tmp/foo/3

This delivers your output as a set of lines to the second program but acts (to the while loop iteration) as a set of inputs as if it were an array.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.