Is there any real benefit to using bash -c 'some command'
over using bash <<< 'some command'
They seem to achieve the same effect.
bashhere-string
Is there any real benefit to using bash -c 'some command'
over using bash <<< 'some command'
They seem to achieve the same effect.
Best Answer
bash -c 'some command'
retains access to the standard input of the caller, soread
or commands reading from standard input will work normally.bash <<< 'some command'
replaces that input with the line being passed in, sobash -c cat
andbash <<< cat
do different things.On the other hand, you could make use of that feature to provide your own standard input to be used through
$'...'
, if you're very careful:I wouldn't want to rely on that, but it could be convenient sometimes.
bash -c
also allows arguments to be passed to the script, and$0
to be set:will set
$1
toabc
and$2
todef
insidesome command
.