You can use command substitution:
oo.sh "$(cat /etc/httpd/conf/httpd.conf)"
This will run cat /etc/httpd/conf/httpd.conf
and put the output (the contents of the file) into the first argument given to oo.sh
. It's quoted, so it gets passed as a single argument — spaces and special characters are passed through untouched. oo.sh
gets a single argument.
More broadly, though, it might be better to pass the filename into the script if possible, or to give the file contents as standard input (oo.sh < /etc/httpd/conf/httpd.conf
). As well as being more standard, there's a maximum length all the command-line arguments put together can be, and a file could be longer than that. Even if it works now, if that file might grow bigger over time eventually passing the whole thing as an argument will stop working with an error "arg list too long".
You can find that limit with getconf ARG_MAX
. The size varies dramatically: I have systems here with 2MB limits and 256KB limits. If your file will always be small you don't need to worry, but otherwise you should try another way of getting the data into the script.
sudo
, but your scripts can? – psimon Jun 21 '14 at 08:16echo "$1"
to avoid severe mangling, or ratherprintf %s "$1"
if you want the argument to be printed out intact in all cases. See http://unix.stackexchange.com/questions/131766/why-does-my-shell-script-choke-on-whitespace-or-other-special-characters – Gilles 'SO- stop being evil' Jun 21 '14 at 12:16