0

I want to put multiple filepaths as a string in bash script, so I can pass this string to another program. When I concatenate these filepaths I get the error: No such file or directory. Bash has to tread this filepath as a string instead of a file...

Im concatenating this way:

all=""
for path in $dir/*; do
    filePath="$path/file.txt"
    $all="$all I=$filePath"
done

echo $all

How can I get this output?

I=first/file.txt I=second/file.txt etc.
4
  • all="$all I=$filePath" have you try without initial $? Commented Dec 5, 2012 at 9:55
  • Something is wrong in your code: you don't use the loop variable path at all... Commented Dec 5, 2012 at 10:00
  • Made a little mistake in making this script simple ;) Problem was what Velthune mentioned... Commented Dec 5, 2012 at 10:17
  • You'd better use arrays! Commented Dec 5, 2012 at 12:55

2 Answers 2

1

Is just your syntax wrong:

all=""
for path in $dir/*; do
    filePath="$dir/file.txt"
    all="$all I=$filePath"    #without $
done
echo $all
Sign up to request clarification or add additional context in comments.

1 Comment

That was the problem... Why bash doesn't give the shell a syntax error instead of saying it is no file or dir -_-
0

Maybe you meant to use path? And don't use $ as a prefix in assignments.

all=""
for path in $dir/*; do
    filePath="$path/file.txt"
    all="$all I=$filePath"
done
echo $all

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.