Purpose of '&& bash' in a command (not the '&&' part, the 'bash' part)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom: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}
bash
add a comment |
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}
bash
What OS are you using?
– Arrow
Jul 2 '17 at 18:35
add a comment |
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}
bash
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}
bash
bash
edited Jul 2 '17 at 18:15
mattst
asked Jul 2 '17 at 17:48
mattstmattst
275212
275212
What OS are you using?
– Arrow
Jul 2 '17 at 18:35
add a comment |
What OS are you using?
– Arrow
Jul 2 '17 at 18:35
What OS are you using?
– Arrow
Jul 2 '17 at 18:35
What OS are you using?
– Arrow
Jul 2 '17 at 18:35
add a comment |
3 Answers
3
active
oldest
votes
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 therm
andchmod
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 themv 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
|
show 1 more comment
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.
add a comment |
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....
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f374830%2fpurpose-of-bash-in-a-command-not-the-part-the-bash-part%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 therm
andchmod
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 themv 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
|
show 1 more comment
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 therm
andchmod
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 themv 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
|
show 1 more comment
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.
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.
edited 2 hours ago
Rui F Ribeiro
41.9k1483142
41.9k1483142
answered Jul 2 '17 at 18:23
Aditya BanerjeeAditya Banerjee
362
362
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 therm
andchmod
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 themv 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
|
show 1 more comment
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 therm
andchmod
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 themv 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
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
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
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
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
@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
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
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
@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
|
show 1 more comment
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.
add a comment |
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.
add a comment |
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.
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.
edited Jul 2 '17 at 22:31
answered Jul 2 '17 at 21:19
jlliagrejlliagre
47.9k786138
47.9k786138
add a comment |
add a comment |
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....
add a comment |
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....
add a comment |
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....
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....
answered Jul 3 '17 at 9:18
user1934428user1934428
459310
459310
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f374830%2fpurpose-of-bash-in-a-command-not-the-part-the-bash-part%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What OS are you using?
– Arrow
Jul 2 '17 at 18:35