Author Topic: Batch modify MLVs using bash on Mac – Help please!  (Read 1238 times)

timbytheriver

  • Senior
  • ****
  • Posts: 476
Batch modify MLVs using bash on Mac – Help please!
« on: October 29, 2021, 12:47:19 PM »
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)
Code: [Select]
$FILES = Get-ChildItem  .\\* -recurse -Include  *.mlv
foreach ($file in $FILES) {
  echo "Processing $file..."
  echo "0000068: FF 3F" | xxd -r - $file
}

Bash (not working)
Code: [Select]
#!/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.
5D3 1.1.3
5D2 2.1.2

names_are_hard

  • Developer
  • Senior
  • *****
  • Posts: 482
  • 200D idiot
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #1 on: October 29, 2021, 02:25:26 PM »
In the Mac attempt, you are using a variable uninitialised, here:
Quote
echo "0000068: FF 3F" | xxd -r - $file

Replace $file with $f.

Bash will happily replace variables that don't exist with an empty string.

timbytheriver

  • Senior
  • ****
  • Posts: 476
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #2 on: October 29, 2021, 02:40:36 PM »
Hey! Thanks, but still the same output with

Code: [Select]
  echo "0000068: FF 3F" | xxd -r - $f
5D3 1.1.3
5D2 2.1.2

names_are_hard

  • Developer
  • Senior
  • *****
  • Posts: 482
  • 200D idiot
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #3 on: October 29, 2021, 03:13:55 PM »
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.

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 8305
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #4 on: October 29, 2021, 03:37:23 PM »
Is shell in macOS case-insensitive for variables? Because $FILE and $file?

timbytheriver

  • Senior
  • ****
  • Posts: 476
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #5 on: October 29, 2021, 05:19:35 PM »
Thanks, but case doesn't seem to make a difference. I have this now:
Code: [Select]
#!/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?  ::)


5D3 1.1.3
5D2 2.1.2

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7267
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #6 on: October 29, 2021, 05:27:09 PM »
Code: [Select]
echo "0000068: FF 3F" | xxd -r - $f"Should be.
Code: [Select]
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?

timbytheriver

  • Senior
  • ****
  • Posts: 476
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #7 on: October 29, 2021, 05:37:04 PM »
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:

Code: [Select]
echo "0000068: FF 3F" | xxd -r - Input.MLV
5D3 1.1.3
5D2 2.1.2

timbytheriver

  • Senior
  • ****
  • Posts: 476
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #8 on: October 29, 2021, 05:46:04 PM »
@Danne

You could be right about the wildcard. If I remove it,

Code: [Select]
FILES="/Users/me/Desktop/media/"
the output is without the crazy characters, now just
Code: [Select]
xxd: /Users/me/Desktop/media/: Is a directory
cat: /Users/me/Desktop/media/: Is a directory

Sheesh!
5D3 1.1.3
5D2 2.1.2

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7267
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #9 on: October 29, 2021, 05:51:30 PM »
What is cat doing here?

If you´re in a folder with mlv files and do this?
Code: [Select]
for f in *.MLV
do
  echo "0000068: FF 3F" | xxd -r - "$f"
done

timbytheriver

  • Senior
  • ****
  • Posts: 476
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #10 on: October 29, 2021, 06:17:56 PM »
get

Code: [Select]
line 2: syntax error near unexpected token `|'
5D3 1.1.3
5D2 2.1.2

timbytheriver

  • Senior
  • ****
  • Posts: 476
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #11 on: October 29, 2021, 06:37:28 PM »
Ok. Thanks all for help. Now it works fine:

Code: [Select]
#!/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).  :)
5D3 1.1.3
5D2 2.1.2

Danne

  • Developer
  • Hero Member
  • *****
  • Posts: 7267
Re: Batch modify MLVs using bash on Mac – Help please!
« Reply #12 on: October 29, 2021, 08:12:15 PM »
Also possible to place a script next mlv files in a folder and double tap it containing following:
Code: [Select]
#!/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.