rusty with simple bash scripts

55 views Asked by At

I'm working out of very old memory here and I just can't see what's wrong with the following little snippet of a script. I isolated the problem to this part >>

#!/bin/sh
for x in   `ls ~/sandbox/inputVids/*.mp4`
do
    echo $x;
    cp "$x" "~/sandbox/outputVids/${x/%.mp4/.silent.mp1}";
done

I keep getting the message

./makeRepeater.sh: 15: ./makeRepeater.sh: Bad substitution

any help appreciated, thanks.

2

There are 2 answers

5
anubhava On BEST ANSWER

Few glitches in your script:

  1. No need to parse ls's output
  2. Tilde ~ is not expanded inside the double quotes
  3. Replacement of string is not using correct pattern
  4. Using wrong shebang i.e. sh instead of bash

Use this script instead:

#!/bin/bash

cd ~/sandbox/inputVids/
for x in *.mp4; do
    echo "$x";
    cp "$x" ~/sandbox/outputVids/"${x/.mp4/.silent.mp1}"
done
0
P.P On

You are sh which doesn't understand bash's parameter substitution. Use bash i.e. put #!/bin/bash as your shebang line.