Scripting bash with Ruby and Variables to run FFMPEG command

Jeremy

I'm trying to create a simply ruby script to run an ffmpeg command through bash to convert an audio file from one format to another.

the command is ffmpeg -i (in file) -acodec libmp3lame -ab 64k -ar 48000 -ac 1 AAA_S00E00_Podcast.mp3

I have a ruby script with the right permissions and that I can call (tested it with a system ls call before moving onto the ffmpeg attempt)

#!/bin/ruby

def mkmp3( one = "", two = "" )
    system "ffmpeg -i #{one} -acodec libmp3lame -ab 64k -ar 48000 -ac 1 #{two}.mp3"
end

mkmp3

but when I call it from bash trying to convert a file called session.flac to smoochie.mp3 I get back:

mkmp3.rb ('session.flac', 'smoochie')
bash: syntax error near unexpected token `'session.flac','
Gerry

The error is because you are using parenthesis ( and ) to add arguments to your ruby script. Remove them and the error will be gone; in fact, you only need to specify your strings separated by a space (otherwise you will get the comma , as a string):

$ mkmp3.rb session.flac smoochie

Now, to use those parameters you need to add ARGV in your script, like this:

#!/bin/ruby

def mkmp3( one = ARGV[0], two = ARGV[1] )
    system "ffmpeg -i #{one} -acodec libmp3lame -ab 64k -ar 48000 -ac 1 #{two}.mp3"
end

mkmp3

ARGV will contain an array of strings with the arguments you added, consider this script (test.rb):

#!/bin/ruby

puts ARGV.inspect

Execute the script:

$ ruby so.rb one two

And the output will be:

["one", "two"]

So you access each value using the array index (i.e. ARGV[0] and ARGV[1]).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Time Variables in Bash Scripting

From Dev

Bash scripting - nested variables

From Dev

How to run a command separated in several variables in Bash?

From Dev

Bash Scripting: automate command in console

From Dev

how to use bash to run a same command with a group of variables?

From Dev

Using variables between files in shell / bash scripting

From Dev

Controlling variables from keyboard bash scripting

From Dev

Bash Scripting: Using Two Variables in IF Statement

From Dev

Trouble using cd command with "~" or "$HOME" in bash scripting

From Dev

Trouble using cd command with "~" or "$HOME" in bash scripting

From Dev

bash scripting and trying to understand an echo command

From Dev

How to do some custom bash scripting command?

From Dev

Bash command using variables

From Dev

Bash variables in command

From Dev

Scripting in Ruby

From Dev

Bash scripting and executable scripting

From Dev

What are the specific naming conventions for variables in bash shell scripting language?

From Dev

Fork command in Background using ampersand (&) when Bash scripting and capture output

From Dev

Linux Bash scripting execute a terminal command on a list of filenames

From Dev

python + run system command with variables

From Dev

bash for loop to run ruby scripts

From Dev

Run a bash function that takes two files names as variables from command line

From Dev

fdisk command run on terminal but not run with ruby script

From Dev

fdisk command run on terminal but not run with ruby script

From Dev

how to run ffmpeg command(windows) in java

From Dev

Run BASH command in JAVA in background

From Java

How to run mysql command on bash?

From Dev

Run a command with sudo in bash shell

From Dev

Run random command in bash script

Related Related

  1. 1

    Time Variables in Bash Scripting

  2. 2

    Bash scripting - nested variables

  3. 3

    How to run a command separated in several variables in Bash?

  4. 4

    Bash Scripting: automate command in console

  5. 5

    how to use bash to run a same command with a group of variables?

  6. 6

    Using variables between files in shell / bash scripting

  7. 7

    Controlling variables from keyboard bash scripting

  8. 8

    Bash Scripting: Using Two Variables in IF Statement

  9. 9

    Trouble using cd command with "~" or "$HOME" in bash scripting

  10. 10

    Trouble using cd command with "~" or "$HOME" in bash scripting

  11. 11

    bash scripting and trying to understand an echo command

  12. 12

    How to do some custom bash scripting command?

  13. 13

    Bash command using variables

  14. 14

    Bash variables in command

  15. 15

    Scripting in Ruby

  16. 16

    Bash scripting and executable scripting

  17. 17

    What are the specific naming conventions for variables in bash shell scripting language?

  18. 18

    Fork command in Background using ampersand (&) when Bash scripting and capture output

  19. 19

    Linux Bash scripting execute a terminal command on a list of filenames

  20. 20

    python + run system command with variables

  21. 21

    bash for loop to run ruby scripts

  22. 22

    Run a bash function that takes two files names as variables from command line

  23. 23

    fdisk command run on terminal but not run with ruby script

  24. 24

    fdisk command run on terminal but not run with ruby script

  25. 25

    how to run ffmpeg command(windows) in java

  26. 26

    Run BASH command in JAVA in background

  27. 27

    How to run mysql command on bash?

  28. 28

    Run a command with sudo in bash shell

  29. 29

    Run random command in bash script

HotTag

Archive