Errors in execution of shell script which consists of command substitution

@rupeshforu3, in addition to all the advice given by other team members, a good habit to form is verifying the integrity of shell scripts by running them through the shellcheck utility (if not installed ask your system admin to install or ask google how to install shellcheck )

for your script (named test.sh for convenience), running it through shellcheck produced following:

shellcheck test.sh

In test.sh line 1:
for i in *.mp4; 
^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.


In test.sh line 4:
 do name=`echo $i | cut -d'.' -f1`; 
         ^-- SC2006: Use $(..) instead of legacy `..`.
               ^-- SC2086: Double quote to prevent globbing and word splitting.


In test.sh line 6:
 echo $name; 
      ^-- SC2086: Double quote to prevent globbing and word splitting.


In test.sh line 9:
 $temp=`ffprobe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1 $i`;
  ^-- SC1066: Don't use $ on the left side of assignments.
       ^-- SC2006: Use $(..) instead of legacy `..`.
                                                                                                          ^-- SC2086: Double quote to prevent globbing and word splitting.


In test.sh line 11:
 $br=`echo $temp | cut -d'=' -f1`; 
  ^-- SC1066: Don't use $ on the left side of assignments.
     ^-- SC2006: Use $(..) instead of legacy `..`.
           ^-- SC2086: Double quote to prevent globbing and word splitting.


In test.sh line 14:
ffmpeg -y -i "$i" -cpucount 3 -c:v libx265 -b:v $br -preset medium -c:a libfdk_aac -b:a 52k -ar 44100 "${name}_compressed.mp4"; 
                                                ^-- SC2086: Double quote to prevent globbing and word splitting.
2 Likes