I want to run a Ruby/Python one-liner in a shell script, like:
python 'print "hello world"'
or
ruby 'puts "hello world"'
or something like that so I can quickly pipe the input elsewhere.
Since version 2.05b, bash can redirect standard input (stdin) from a "here string" using the <<< operator.
$ python <<< 'print "hello world"'
hello world
$ ruby <<< 'puts "hello world"'
hello world
Each of these commands has a switch to execute a string passed as an argument. For python, it's -c:
$ python -c 'print "hello world"'
hello world
For ruby, it's -e:
$ ruby -e 'puts "hello world"'
hello world
By the way, the output of python --help, ruby --help or looking in the man page for either program would give you the answer.
In Perl, from command line:
perl -e 'print "Hello World\n";'
Or inside bash script:
#!/bin/bash
perl -e 'print "Hello World\n";'
perl -E 'say "Hello World"'. You don't need the ; at all. Actually OP was not asking for a line break though.If you mean using a one liner of perl/awk/python in a pipe, it is just like most other Unix utilities:
$ python -c 'print "hello"' | tr "[a-z]" "[A-Z]"
HELLO
$ ruby -e 'puts "hello"' | tr "[a-z]" "[A-Z]"
HELLO
$ python -c 'print "GREETINGS"' | perl -lpe 's/([EI])/lc($1)/ge'
GReeTiNGS
You need neither Perl, Python or Ruby to pipe a fixed string to another application. The echo program can be used for that.
$ echo 'foo' | cat
foo
See explainshell.com for more infos.