2015-06-20 59 views
1

我正在使用非常古老的内存,我只是无法看到脚本的以下小片段出了什么问题。我孤立的问题,这部分>>用简单的bash脚本生锈

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

我不断收到消息

./makeRepeater.sh:15:./makeRepeater.sh:坏替代

任何帮助表示感谢。

+1

哪一行是15行?代码发布看起来很好。也许,你没有使用bash和其他shell,或者在顶部有错误的shebang?第一行是否有'#!/ bin/bash'? –

+0

有问题的行是前一行。是的,该文件以#!/ bin/sh – Slabo

+0

ubuntu @ ip-17开头:〜/ sandbox $ ls -l/bin/sh lrwxrwxrwx 1 root root 4 Feb 19 2014/bin/sh - >破折号 – Slabo

回答

1

一些小问题在你的脚本:

  1. 无需ls的输出
  2. 波浪号~没有双引号
  3. 替换字符串的内部扩展没有使用正确的方式来解析
  4. 使用错误的shebang即sh而不是bash

请使用以下脚本代替:

#!/bin/bash 

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

感谢您的快速回复。我按照你的说法改正了脚本,但是我仍然在第15行得到同样的错误.. – Slabo

+0

erorr :: ubuntu @ ip-71:〜/ sandbox $ ./makeRepeater.sh /home/ubuntu/sandbox/inputVids /VID-20150504-WA0003.mp4 ./makeRepeater.sh:15:./makeRepeater.sh:错误替代 – Slabo

+0

必须是因为$ x是/home/ubuntu/sandbox/inputVids/VID-20150504-WA0003.mp4?我的意思是,而不是只是VID-20150504-WA0003.mp4 – Slabo

0

你是sh它不理解bash的参数替换。使用bash即将#!/bin/bash作为您的shebang线。