The $1 is a positional variable. So if you run ./script.sh arg1 $1 would be arg1 in that example, $0 would be the ./script.sh. It’s the simplest way to pass an argument to a script.
So… huh? What role does this play, since all the lines in the picture have $1? If you run it with arg1, won’t it run them all? And if you left out arg1 and also didn’t add $1 to each line, wouldn’t it also just run all of them?
Yes, that is the intention. When you’re following some guide online and it requires you use some “software”, you may not know how to install that software.
This install.sh script tries package managers, because one of them will probably work. Others will fail.
For example, installing numpy (python package): pip install succeeds and all the other ones (hopefully) fail.
Installing libcurl4-openssl-dev (curl with openssl library file): apt-get install works and all other ones (hopefully) fails.
Never thought about it, but wouldn’t that just fail after the first one it fails to find? I think most install commands return nonzero if nothing is installed
I don’t get it. Looks like a script that runs all these things, but I don’t get the one dollar.
The
$1is a positional variable. So if you run./script.sh arg1$1 would be arg1 in that example, $0 would be the ./script.sh. It’s the simplest way to pass an argument to a script.So… huh? What role does this play, since all the lines in the picture have $1? If you run it with arg1, won’t it run them all? And if you left out arg1 and also didn’t add $1 to each line, wouldn’t it also just run all of them?
Yes, that is the intention. When you’re following some guide online and it requires you use some “software”, you may not know how to install that software.
This install.sh script tries package managers, because one of them will probably work. Others will fail.
For example, installing numpy (python package): pip install succeeds and all the other ones (hopefully) fail.
Installing libcurl4-openssl-dev (curl with openssl library file): apt-get install works and all other ones (hopefully) fails.
Longer and more thorough explanation:
https://www.explainxkcd.com/wiki/index.php/1654:_Universal_Install_Script
Never thought about it, but wouldn’t that just fail after the first one it fails to find? I think most install commands return nonzero if nothing is installed
Should probably use or instead of and
Nope, this launches all those commands in parallel. Logical and is
&&.This one hurts.