pythonbashshellubuntulibx265

Shell script is not running in ubuntu


I have the following script in a bash script encode.sh.

echo "1 configuration out of 936"
x265 incident_10d_384x288_25.yuv --input-res 384x288 --fps 25 str/incident_10d_384x288_25_QP_0_ON_B0.bin --tune psnr --psnr --preset medium --max-merge 5 --merange 64 --no-open-gop -I 48 -i 8 --tu-intra-depth 3 --tu-inter-depth 3 --input-depth 8 --aq-mode 0 --b-adapt 0 --scenecut 48 --ref 4 --sao --deblock=0:0 --bframes 0 --qp 0 --csv-log-level 2 --log-level 4 --csv csv/incident_10d_384x288_25_QP_0_ON_B0.csv > txt/1_incident_10d_384x288_25_QP_0_ON_B0.txt 2<&1 
echo "2 configuration out of 936"
x265 incident_10d_384x288_25.yuv --input-res 384x288 --fps 25 str/incident_10d_384x288_25_QP_1_ON_B0.bin --tune psnr --psnr --preset medium --max-merge 5 --merange 64 --no-open-gop -I 48 -i 8 --tu-intra-depth 3 --tu-inter-depth 3 --input-depth 8 --aq-mode 0 --b-adapt 0 --scenecut 48 --ref 4 --sao --deblock=0:0 --bframes 0 --qp 1 --csv-log-level 2 --log-level 4 --csv csv/incident_10d_384x288_25_QP_1_ON_B0.csv > txt/2_incident_10d_384x288_25_QP_1_ON_B0.txt 2<&1 
echo "3 configuration out of 936"
x265 incident_10d_384x288_25.yuv --input-res 384x288 --fps 25 str/incident_10d_384x288_25_QP_2_ON_B0.bin --tune psnr --psnr --preset medium --max-merge 5 --merange 64 --no-open-gop -I 48 -i 8 --tu-intra-depth 3 --tu-inter-depth 3 --input-depth 8 --aq-mode 0 --b-adapt 0 --scenecut 48 --ref 4 --sao --deblock=0:0 --bframes 0 --qp 2 --csv-log-level 2 --log-level 4 --csv csv/incident_10d_384x288_25_QP_2_ON_B0.csv > txt/3_incident_10d_384x288_25_QP_2_ON_B0.txt 2<&1 

I want to write the output of each encoding from terminal to a txt file using > txt/3_incident_10d_384x288_25_QP_2_ON_B0.txt 2<&1. I create the bash script from windows using python 2.7 and I want to run it in ubuntu.

When I copy a line from bash script and run it in terminal it's working. But when I want to run it from batch file it's not working.

I get no error in terminal but the x265 encoder does not run with a warning:

[warning]: extra unused command arguments given <

Is there any special character in my shell script?

Do you know how to fix this?


Solution

  • Output redirection uses >&, not <&. That would be

    2>&1 or 1>&2

    (probably the first one, redirect standard error (2) to standard output (1) )

    related question on Stack Overflow : How can I redirect and append both stdout and stderr to a file with Bash?


    EDIT:

    Apparently, you also had the error message in the other order :

    [warning]: extra unused command arguments given >`

    which is more surprising.

    As per our small discussion in comments, it was due to incorrect line endings handling. Probably the whole script was seen as only one big line, which would explain that bash was surprised to see several redirections.

    For information, in case comments get deleted : using Notepad++ menu Edit > EOL Conversion solved the issue. More info here : EOL conversion in notepad ++