Reputation: 1949
I'm writing a bash script Test.sh
that aims to execute anotherscript
(a linux executable file):
#!/bin/bash -l
mp1='/my/path1/'
mp2='/my/path2/anotherscript'
for myfile in $mp1*.txt; do
echo "$myfile"
"$mp2 $myfile -m mymode"
echo "finished file"
done
Notice that anotherscript
takes as arguments $myfile
and options -m mymode
.
But I get the file not found error (says Test.sh: line 8: /my.path2/anotherscript: No such file or directory
).
My questions are:
Upvotes: 2
Views: 1426
Reputation: 401
I suggest you use
sh -c "$mp2 $myfile -m mymode"
instead of just
"$mp2 $myfile -m mymode"
Upvotes: 2
Reputation:
#!/bin/bash -l
dir=`find /my/path1/ -name "*.txt"`
mp2='/my/path2/anotherscript'
for myfile in "$dir"; do
echo "$myfile"
"$mp2" "$myfile" -m mymode
echo "finished file"
done
Make sure anotherscript
has execution right (chmod +x anotherscript
).
Upvotes: 0