私はsource
を使用して、bashスクリプトからその文字列を実行するために生成された変数をファイルから文字列に挿入します。埋め込み引用符(ソースパラメータ)を含むコマンドを実行するとBashスクリプトが失敗する
私は生成された文字列をコマンドラインから動作するものと比較するためにエコーしましたが、違いは見えないようですが、bashコマンドは失敗しました。中間。
私はice_name文字列を二重引用符をエスケープしてきたので、それは私がそれ
をエコーするとき、私は他の文字をエスケープする必要がありますか働くものと同じに見えますか?
これは、コマンド
avconv -re -i test.mp3 -c:a libmp3lame -content_type audio/mpeg -b:a 128k -legacy_icecast 1
-ice_name "Raspi Test Stream of MP3" -f mp3
icecast://:[email protected]/my/mount/point/url
ない、それはあなたがソースのファイルベンが必要ですが、念のためにここにある場合は確実である、BEFORE -ice_name
パラメータ
を混入しているようです
#!/bin/bash
#
# stream.cfg
#
# WiFi Settings
#
wifi_name=mywifi
wifi_password=mywifipwd
#
# Icecast Server Settings
#
icecast_server=icecast.server.com
icecast_port=443
icecast_mount_url=/user/mountpt/url
icecast_show="RPi Demo Show - autostart"
icecast_description="Test of Stream from RPi USB Audio to Spreaker"
icecast_user=""
# Source password
icecast_password=sourcepwd
#
# avconv setting for Raspbian Jessie Lite
# may not need if you're using a self compiled ffmpeg version
#
icecast_legacy=1
#
# Stream Settings - probably not safer to go higher unless great internet connection
#
stream_bitrate=128k
設定ファイルを処理して、包まれた文字をエスケープしない文字列に引用符を埋め込むmコマンド
#!/bin/bash
#
# autostart-settings.sh
#
# Load in config file settings
CONFIG_FILE=~/autostart/autostart-settings.cfg
# Check if file exists
echo "does file exist"
if [ ! -f "$CONFIG_FILE" ]; then
echo "Config File: $(CONFIG_FILE) does not exist"
exit 1
else
# process settings
echo "running source on $CONFIG_FILE"
source "$CONFIG_FILE"
fi
start_cmd="avconv -re -i /home/pi/test.mp3 -c:a libmp3lame -content_type audio/mpeg -b:a $stream_bitrate -legacy_icecast $icecast_legacy"
stream_parameters="-ice_name \"$icecast_show\" -f mp3"
icecast_setup="icecast://$icecast_user:[email protected]$icecast_server:$icecast_port$icecast_mount_url"
test_cmd="$start_cmd $stream_parameters $icecast_setup"
echo "Testing command: $test_cmd"
# Run command
$test_cmd
ファイルをソースした後にコマンドを生成するために使用するコマンドは何ですか?私はあなたが文字通りの引用に犠牲になっていると思う。 'echo" foo "'と 'bar = '" foo "'; echo $ bar'は同一ではありません。 – chepner
ちょうど$ streamcmdを使用しています - エコーはありません。または、すべてのマージと連結を行うスクリプトを参照したいですか? – dbmitch
オリジナルの質問に追加されたスクリプト – dbmitch