I'm trying to create a bash script to run the ffmpeg command on every file in a directory with filenames that contain spaces. This is the script that I started with to do an individual file which works properly. I use tab to populate the filename argument which includes an escape character for all the spaces:
#!/bin/bash input="./"$1 output="/xfer/transfer/temp/"$1 ffmpeg -i "${input}" -c:v copy -c:a libfdk_aac -b:a 160k "${output}" Next step is to perform the ffmpeg command on all files in a directory. Let's say the directory looks like this with the ls command:
'Name of First File.mkv' 'Name of Second File.mkv' Here's my test code:
#!/bin/bash files=$(ls *) for input in ${files} do echo $input done My problem is the output looks like this:
Name of First File.mkv Name Of Second File.mkv Adding a -b to the ls command simply adds a backslash to the end of every line. I need help with making $input look like Name of First File.mkv, etc.
lsoutput for anything.lsis a tool for interactively looking at directory metadata. Any attempts at parsinglsoutput with code are broken. Globs are much more simple AND correct:for file in *.txt. Read mywiki.wooledge.org/ParsingLs"$var","$(command "$var")","${array[@]}","a & b". Use'single quotes'for code or literal$'s: 'Costs $5 US',ssh host 'echo "$HOSTNAME"'. See <mywiki.wooledge.org/Quotes> <mywiki.wooledge.org/Arguments> <web.archive.org/web/20230224010517/https://…> when-is-double-quoting-necessary