Hi
I'm trying to run a command on Mac OS in Terminal to batch modify a folder of MLV files to rewrite their WhiteLevel.
I have a [working on PC] Powershell command that I'm attempting to rewrite into bash that is not working on Mac so far. When I run it, the terminal beeps, and the screen is filled with a flood of random characters until I stop it. The mlvs remain unmodified.
Can someone help please?
Powershell (working)
$FILES = Get-ChildItem .\\* -recurse -Include *.mlv
foreach ($file in $FILES) {
echo "Processing $file..."
echo "0000068: FF 3F" | xxd -r - $file
}
Bash (not working)
#!/bin/bash
FILES="/Users/me/Desktop/media/*.mlv"
for f in $FILES
do
echo "0000068: FF 3F" | xxd -r - $file
cat "$f"
done
Many thanks.
In the Mac attempt, you are using a variable uninitialised, here:
Quoteecho "0000068: FF 3F" | xxd -r - $file
Replace $file with $f.
Bash will happily replace variables that don't exist with an empty string.
Hey! Thanks, but still the same output with
echo "0000068: FF 3F" | xxd -r - $f
Sorry, don't have a Mac, so I have no way to test. I don't see any other mistakes, but I try and avoid using shell scripts, because they are hard to debug. So I'm not very good at them.
Is shell in macOS case-insensitive for variables? Because $FILE and $file?
Thanks, but case doesn't seem to make a difference. I have this now:
#!/bin/bash
FILES="/Users/me/Desktop/media/*.MLV"
for f in $FILES
do
echo "0000068: FF 3F" | xxd -r - $f"
cat "$f"
done
Random gibberish output has been replaced with this:
line 6: unexpected EOF while looking for matching `"'
line 8: syntax error: unexpected end of file
A Google search reveals stuff about making sure text editor is using correct double quotes – which Sublime text is.
Anyone spot any schoolboy errors? ::)
echo "0000068: FF 3F" | xxd -r - $f"
Should be.
echo "0000068: FF 3F" | xxd -r - "$f"
Still, not sure your wildcard line will work but try around some and you´ll probably find the right syntax. Is xxd applying the change on a single file, tested that?
Thanks. Looked promising – as the code syntax highlighting in Sublime Text looked more correct – but now random characters on output has returned!
Original command on a single file always worked. I used this:
echo "0000068: FF 3F" | xxd -r - Input.MLV
@Danne
You could be right about the wildcard. If I remove it,
FILES="/Users/me/Desktop/media/"
the output is without the crazy characters, now just
xxd: /Users/me/Desktop/media/: Is a directory
cat: /Users/me/Desktop/media/: Is a directory
Sheesh!
What is cat doing here?
If you´re in a folder with mlv files and do this?
for f in *.MLV
do
echo "0000068: FF 3F" | xxd -r - "$f"
done
get
line 2: syntax error near unexpected token `|'
Ok. Thanks all for help. Now it works fine:
#!/bin/bash
FILES="/Users/me/Desktop/media/*.MLV"
for f in $FILES
do
echo "0000068: FF 3F" | xxd -r - "$f"
done
Save as foo.sh script, run chmod u+x on it, and run it from anywhere (not within the MLV folder itself). :)
Also possible to place a script next mlv files in a folder and double tap it containing following:
#!/bin/bash
cd "$(dirname "$0")"
for f in *.MLV
do
echo "0000068: FF 3F" | xxd -r - "$f"
done
Name the script foo.command and run chmod u+x on the script before double tapping.