2016-07-05 57 views
0

我一直在試圖創建一個腳本來使用ffmpeg的網站下載的文件,它工作得很好,直到它得到的文件名,代碼是這樣:ffmpeg的不採取對文件名變量在bash

echo "Hello, this is the basic script to download videos. This requires ffmpeg to be installed, do you want to start? (Y/N)" 
read start_input 
if [ $start_input = Y ] || [ $start_input = y ] 
then 
    echo "[Text]" 
    read video_link 
    echo "Now I need what quality you want the video to be (240, 360, 480, 720, 1080, Default: 720)" 
    read quality_link 
    if [ -z $quality_link ] 
    then 
     $quality_link = "720" 
    fi 

    echo "Now name the new file (Note, it will have a .ts extention)" 

    read $new_file 
    echo "And where would you like it to be placed?" 
    read $folder_location 
    $file="${folder_location}/${new_file}.ts" 
    ffmpeg -i "[url]" -c:v copy -c:a copy -f mpegts $file 
else 
    exit 0 
fi 
exit 0 

問題是什麼時候使用$ file變量,ffmpeg沒有使用它,變量被完全忽略,我嘗試了許多不同的方法,但他們不工作(單引號,雙引號,使用$ {file}) , 我能做什麼?

+4

歡迎使用stackoverflow!給[shellcheck](http://shellcheck.net)一個嘗試 - 在這種情況下它說「不要在作業左側使用$」。還有其他一些建議。 –

+0

您可以使用'-c copy'而不是'-c:v copy -c:a copy'來保存幾位數據。 – LordNeckbeard

+0

其他人,我已經試過這個,但它不起作用,我試過用斜線分隔的原始輸入,它試圖寫/所以這不是問題 – 2haloes

回答

2

要assing給一個變量在bash,請使用以下語法:

var=value 
var1=$var2 

在左側沒有美元符號,圍繞=標誌沒有空格。

+0

這是誤導性陳述。這意味着'a = $ b'是錯誤的,因爲'$'在'='符號的周圍。 – alvits

+0

正如在上面的評論中所說的那樣,即使做出這樣的改變,這也不是問題,ffmpeg在工作中沒有區別 – 2haloes

+0

@ 2haloes:也從'read $ variable'中刪除美元符號。 – choroba