Sos
Sos

Reputation: 1949

Running executable file with additional options or arguments

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:

  1. I have followed this question to get my bash script to run the executable file. But I'm afraid I still get the error above.
  2. Am I specifying arguments as they should to execute the file?

Upvotes: 2

Views: 1426

Answers (2)

Tom Atix
Tom Atix

Reputation: 401

I suggest you use

sh -c "$mp2 $myfile -m mymode"

instead of just

"$mp2 $myfile -m mymode"

Upvotes: 2

user6435535
user6435535

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

Related Questions