0

I am trying to write a simple bash script that executes the command tcprobe -i $1 where $1 is an mp4 file. Then, I want to write the output of this command, which should be a long string of information about the video file, to a file called frameInfo.

My code currently is:

#/bin/bash
echo (tcprobe -i $1) > frameInfo

However, this writes the output of tcprobe to the file.

3

You don't need your echo nor parenthesis here. Checking $1 was defined could be relevant as well:

#!/bin/sh

if test "$#" -eq 0; then
    echo missing argument
    exit 1
fi >&2

if test "$DEBUG"; then
    set -x
    tcprobe -i "$1"
    echo returned $?
    set +x
else
    tcprobe -i "$1" >frameInfo 2>&1
fi

exit 0

use DEBUG=toto ./your/script yourFileArgument, to enable debugs.

  • If echo fails, that fails to exit the script. It's better to use proper if/then constructs here than to chain &&d commands. – Stéphane Chazelas Nov 13 '16 at 22:44
  • This ended up not writing anything to the file. I added an echo $1 as an additional check, and it printed the proper value. – acn3 Nov 13 '16 at 23:01
  • You can try running that script commenting out the last redirection (starting at >frameInfo, insert a #) to confirm the command is properly running. Isn't there an error message at least? – SYN Nov 13 '16 at 23:12
  • Unfortunately, your edit did not fix my problem. – acn3 Nov 13 '16 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.