Tag Info

New answers tagged


set isn't just a builtin, it is a POSIX special builtin. There are a few builtin commands which are standards-specified to be found in a command search before anything else - $PATH is not searched, function names are not searched, and etc. Most builtins which are not special are actually required by the POSIX standard to be found in your $PATH before the ...


The problem is that set is a shell builtin and the best solution would be to use a different name for your executable program. Incidentally, last week, I asked a question on how to run system commands instead of shell builtins with the same name and the solution I accepted was to run the command through env: env set 2 3 For this particular case, where ...


Instead of using which, which doesn't work when you need it most, use type to determine what will run when you type a command: $ which set ./set $ type set set is a shell builtin The shell always looks for builtins before searching the $PATH, so setting $PATH doesn't help here. It would be best to rename your executable to something else, but if your ...


set is a builtin in bash (and probably most other shells). This means that bash will not even search the path when looking for the function. As a side remark, I would strongly advice against adding . to the path for security reasons. Imagine for example cding out of /tmp after any other user added an executable file /tmp/cd.


In this very specific case, the command pgrep is an exact match for the need. In a general sense, a function works. From "file command": fcmd(){ local a=$1; shift; $(which "$a") "$@"; } call as fcmd kill -p httpd But if you need less typing, there is no shorter way than a good alias. From the concept "list pid" (lp): alias lp='/bin/kill -p' ...


If you know a solution that requires some typing and you want a solution that requries less typing, build it: runFile() { local cmd="$1"; shift; cmd="$(which "$cmd")" && "$cmd" "$@"; } Abbreviating stuff that normally takes some effort is what computers excel at.


You can prefix any command name with an = sign to get the system version instead of a builtin. This is also a handy way to dodge any aliases that mess up a specific scenario. $ =kill -p httpd


Assuming env is in your path: env kill -p http env runs the executable file named by its first argument in a (possibly) modified environment; as such, it does not know about or work with shell built-in commands. This produces some shell job control cruft, but doesn't rely on an external command: exec kill -p bash & exec requires an executable to ...


The simplest way to do what you want might be to put the line alias kill="/bin/kill" into your ~/.bashrc file. After that, each new login/invocation of bash will interpret "kill" as /bin/kill.


you should handle that stuff in the index evals. and you can indirect through your indirection variable's indices if you make it an array. a=(abc1 def2 ghi3 jkl4 mno5) r=('a[c=${#a[@]}]' a\[i] a\[@]) for i in 0 1 2 3 4 5 do c= printf "<%s>\n" "${!r-${!r[i<c?1:2]}}" printf "\n\tindex is $i and count is $c\n\n" done ...


bash 4.3 namerefs are a godsend. However, you can do this: $ myArr=(A B C D) $ NAME=myArr $ tmp="${NAME}[@]" $ copy=( "${!tmp}" ) $ echo "${#copy[@]}" 4

Top 50 recent answers are included