If which




















The only way for this to fail would likely be to mis-type the name of the program. Outside of that, it should work under any condition. Adrien 1, 1 1 gold badge 16 16 silver badges 35 35 bronze badges. Klevin Kona Klevin Kona 1 1 gold badge 2 2 silver badges 14 14 bronze badges. Yes i added this command if you need to install a package in the sevrer, Open suse, centos, Debian — Klevin Kona.

The syntax highlighting is off in the "echo" line. What is the solution? Does it suggest the Bash script should be different? PeterMortensen Syntax highlighting is off because it doesn't recognize it's a string. I wanted the same question answered but to run within a Makefile. Please install it. Good point. However, when run from inside a bash script, aliases are not visible. There's also a problem, it will return false when the command 'alias' is checked.

When it should return true. Example: test "alias" — Basil Musa. It does this by searching the PATH for executable files matching the names of the arguments. OPTIONS -a print all matching pathnames of each argument EXIT STATUS 0 if all specified commands are found and executable 1 if one or more specified commands is nonexistent or not executable 2 if an invalid option is specified The nice thing about which is that it figures out if the executable is available in the environment that which is run in - it saves a few problems Adam Davis Adam Davis Also note that which may not be available on some minimal systems, though it should be present on any full fledged installation Don't rely in the exit status of which.

Many operating systems have a which that doesn't even set an exit status other than 0. My setup for a Debian server: I had the problem when multiple packages contained the same name. For example apache2. It can give you completely different output. It can give you no output at all. The differences are caused by the difference between interactive and non-interactive mode of the shell. The second one looks odd though, because this must be caused by a difference in PATH environment variable, but subshells inherit the environment.

In my case. The problem can be workarounded by calling a script with a ss Sourcing scripts that are not supposed to be sourced is a bad idea. All I was trying to say is that your answer has little to do with the question being asked and much to do with Bash and its non- interactive mode.

If it explained what is going on in these cases, it would be a helpful addendum to an answer. This is not poxis. Not work in modern distors debian based.

If not exists return "time not found" — abkrim. Setting a key in this array defines a new entry in this table in the same way as with the hash builtin.

Martin von Wittich Martin von Wittich 1 1 gold badge 6 6 silver badges 17 17 bronze badges. Try it. I second the use of "command -v". My final Bash script was as follows Ubuntu server : if! Greg K Greg K 9, 10 10 gold badges 41 41 silver badges 57 57 bronze badges. The conditional is rather useless, modulo the startup time to run apt-get, as apt-get will be satisfied and exit if git-core is already installed.

Its startup time is non-negligible, but the more important motivation is sudo : without the conditional, it would always stop and ask for password unless you did a sudo recently. BTW, it may be useful to do sudo -p "Type your password to install missing git-core: " so the prompt doesn't come out of the blue.

Why is this being upvoted? On which systems does this actually work for you? This fails for me in bash , ksh93 , zsh , busybox [a]sh and dash all of which provide type as a shell builtin. Which introduces non-defining clauses. Sometimes, these phrases are set off by commas. My bike, which has a broken seat, is in the garage. Here, the broken seat is simply a description of the bike in the garage. Do you see the difference? Perhaps a little mnemonic device will help you to remember how to choose between that or which.

They are disposable, and so are clauses with which. Jake Kleinman. The Hydra Stomper returns. The Watcher has a history of breaking his own rules to interfere. Will evil Doctor Strange return in Multiverse of Madness? Post-apocalypse Black Widow and Hawkeye R. The explanation in this link clearly and briefly differentiates the meanings and the inference direction of "if" and "only if".

Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. If and only if, which direction is which? Ask Question. Asked 11 years, 3 months ago. Active 2 years, 3 months ago. Viewed 7k times.



0コメント

  • 1000 / 1000