0

I just saw the list of commands below on a web page - they install a static version of ffmpeg in the user's ~/bin directory. The commands are not part of a script, the user is supposed to copy and paste the commands into the shell. I didn't need or use the commands but...

My question concerns the first command: mkdir -p ~/bin && bash

What is the purpose of using bash in the command? Of course I know what && does and presumably bash just starts a new instance of bash but why would it be necessary to start a new instance of bash? Or does bash, when used like this, have some other purpose?

mkdir -p ~/bin && bash
wget -qO ~/ffmpeg.tar.gz http://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xz
tar xf ~/ffmpeg.tar.gz && cd && rm -rf ffmpeg-*-64bit-static/{manpages,presets,readme.txt}
cp ~/ffmpeg-*-64bit-static/* ~/bin
chmod 700 ~/bin/{ffmpeg,ffprobe,ffmpeg-10bit,qt-faststart}
cd && rm -rf ffmpeg{.tar.gz,-*-64bit-static}
  • What OS are you using? – Arrow Jul 2 '17 at 18:35
2

Some programs require you to be signed in with the bash shell to work correctly, this might be the reason why && bash is used.

The && operator succeeds in executing the second command only if the previous command had worked correctly- but you knew that already, so my guess is the the software youre trying to install requires a bash shell and other shells might not work properly with the given program.

  • 1
    In this case I think it's just a quick'n'dirty way to get the user into a shell that is (a) reasonably likely to be installed on their system and (b) reasonably likely to understand the subsequent brace expansions – steeldriver Jul 2 '17 at 18:30
  • I see, so the command just ensures that bash is running for the subsequent commands, rather than some other shell. The only part of the subsequent commands that look like they could be shell dependant are the {} groupings in the rm and chmod commands. The bash man page says these are a { list; } known as a group command - new to me. The braces {} are reserved words, hance why bash is needed over some other shell. – mattst Jul 2 '17 at 18:37
  • 1
    @mattst that's the idea, but actually it's brace expansion in this case (not command grouping) – steeldriver Jul 2 '17 at 18:56
  • Thanks for the info. and link - all has now been clarified. Brace expansion looks useful, it was worth asking the question to find out about them, commands like the mv foobar.{o,exe} obj example will come in handy. – mattst Jul 2 '17 at 19:07
  • 1
    @JeffSchaller This is not a script but commands to be copy/pasted thus no waiting interactive shell issue here. – jlliagre Jul 2 '17 at 21:22
1

The installation instructions are somewhat broken.

Should the shell code posted had been a shell script, the && bash part would have been essentially useless as it would have launched an interactive bash and stayed there until the user exit the shell with Control-D or exit, then resume executing the next commands with the current user's shell, whatever it is.

But as you wrote, the user is expected to copy and paste the code. In that case, the && bash is conditionally launching bash if the mkdir succeeds, and then the remaining lines are executed by that interpreter. So far so good.

The first issue is what happens in the (unlikely) case the mkdir command fails. The bash interpreter is not executed but all remaining lines, assuming the whole block of shell commands have been copy/pasted, will be executed anyway. Moreover, they will be executed by whatever shell the user is running so possibly one that doesn't understand the curly braces expansion. There will also be errors with all commands referring to the missing ~/bin directory.

The second issue is that even in the first case (mkdir succeeds), the sequence of commands is bogus as it assumes the user is in its home directory when the commands are launched but of course, this is not necessarily the case.

0

Unless the directory bin did not exist before and its creation failed, an interactive bash shell is opened, where you can work as you like .... edit file, write emails to your grandmother, and so on. As soon as you exit this shell, the script continues running, doing the wget, the tar and so on.

Now that's what this script acutally does. Whether or not this is something sensable, I don't want to judge....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.