I tend to do config loaders around commands like ffmpeg, magick, tidy, httrack. Just too much to research the switches each time you need them.
Linux
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by AlpΓ‘r-Etele MΓ©der, licensed under CC BY 3.0
i'm also a noob, but why not just do something like
#!/bin/sh
ffmpeg (options) "$1"
and run the script as ./script.sh filename.mkv?
First, did you look if the filename itself contains a trailing whitespace? I had this issue a few times myself, thinking the script is broken, but in fact the file on the filesystem had a space. That is annoying. If your variable has an additional space and you want to remove it, then I think its better to find out where this space comes from (if its not the file itself), and solve the issue there. Because if you get an unexpected space, then this could be a bug in your script somewhere.
There are multiple ways to remove leading and trailing whitespaces with Bash. The best is not to call a command for this and rely on Bash substitution. This can get ugly, but luckily we can steal from Stack Overflow, :p (basically what we did before Ai):
trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var"
}
trim " text in the middle "
https://stackoverflow.com/questions/369758/how-can-i-trim-whitespace-from-a-bash-variable (who got it from another source,
If the filename has a space, a good solution without adjusting the files is to use quotes: "$FILENAME-synced.mkv"
Edit: generally, as a good practice, quote all variables. If you had FILENAME="my file"and tried to use it asffprobe $FILENAMEit wouldn't work, because variables are evaluated *before* interpreting the command, so effectively it evaluates toffprobe my file(two arguments).ffprobe "$FILENAME"on the other hand evaluates toffprobe "my file"` (onr argument) and works properly no matter the file name.
Or better rename the file. A trailing whitespace in a filename is most likely an error and not what you want to have. As this is about trailing whitespace, not just somewhere in the middle. In general I assume the user already tried and uses quotes.
For trailing whitespace agreed, but a whitespace in the middle of the file is not uncommon and should be properly handled.
I know that and didn't say anything against it. Just saying the question is about trailing whitespaces and my suggestion was to look if the file contains trailing whitespace or if its a script error adding a whitespace to the variable. We don't know so much about the issue.
FILENAME='birthday_0' $(cat command_ffmpeg_SYNCAUD)
cat prints out a file without altering it's contents.
If it's important to keep the commands in a separate file, you could use sed to find/replace, or use eval, or use some external template engine (lookup "bash expand variables in file").
What you probably want to do instead, I assume, is to replace the external files with regular bash variables:
filename="some-file"
command="ffmpg -i ${filename}.mpg -bla -blabla ${filename}.mkv"
echo "$command"
Thanks! "Solving" it with bash does seem to be the easiest way forward. I'll fiddle around with it some! :D
Why are you not simply writing a script with an argument? Why this cat indirection with environment variables?
Because I'm a dog person.
Also, I don't know scripting. :)
A script is just a list of commands. You can likely already execute your file as bash <filename> and get the same result. To use arguments, simply refer to them by number ($1 is the first argument, etc.).
Bonus: you can use a shebang to make it feel like an executable. Put #/bin/bash as the first line, then make it executable via chmod +x <filename>, and now yoi can run it like ./<filename>
A shebang needs a bang!
#!/bin/bash
Thanks! Typed this on mobile, must have missed the key
Haha, all good
Awesome! :D I'll try this immediately after finishing showering. πββοΈπ€£ Thanks!
can't you
tr "endofthefilename " "endofthefilename" ?
I'll have to check tr out. Thanks!
i was studying rename command today and experimenting with empty spaces to see what i can do.
i see that you already solved your problem. This may help on another occasion: a quick fix to replace all " " with a "-"
file-rename 'y/ /-/' ./*
