找不到bash脚本命令

时间:2014-08-20 07:25:21

标签: linux bash ubuntu

我试图运行这里写的bash脚本:Link

我修改了上面的脚本:


#!/bin/bash

keyFile=video.key
openssl rand 16 > $keyFile
encryptionKey=cat $keyFile | hexdump -e '16/1 "%02x"'

splitFilePrefix=stream
encryptedSplitFilePrefix=enc/${splitFilePrefix}

numberOfTsFiles=ls ${splitFilePrefix}*.ts | wc -l

for (( i=1; i<$numberOfTsFiles; i++ ))
 do
 initializationVector=printf '%032x' $i
 openssl aes-128-cbc -e -in ${splitFilePrefix}$i.ts -out ${encryptedSplitFilePrefix}$i.ts -nosalt -iv $initializationVector -K $encryptionKey

像这样运行脚本:./script.sh

但是bash仍然这样大喊:

./script.sh: line 5: video.key: command not found

./script.sh: line 10: stream0.ts: command not found
0

./script.sh: line 17: syntax error: unexpected end of file

我不知道为什么......

我搜索了错误并检查了~/.rnd owner.sh file chmod +x$PATH个问题,但所有问题都无法解决。

1 个答案:

答案 0 :(得分:2)

这一行:

encryptionKey=cat $keyFile | hexdump -e '16/1 "%02x"'

正在尝试执行cat,但您没有使用command substitution。它应该是:

encryptionKey=$(cat "$keyFile" | hexdump -e '16/1 "%02x"')

同样,你需要:

numberOfTsFiles=$(ls ${splitFilePrefix}*.ts | wc -l)

并且需要在循环之后完成:

for (( i=1; i<$numberOfTsFiles; i++ ))
do
   # ...
done