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.

1 Answer 1

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.

4
  • If echo fails, that fails to exit the script. It's better to use proper if/then constructs here than to chain &&d commands. Commented Nov 13, 2016 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. Commented Nov 13, 2016 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? Commented Nov 13, 2016 at 23:12
  • Unfortunately, your edit did not fix my problem. Commented Nov 13, 2016 at 23:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.