Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [shell-builtin]

A shell builtin is a command called from a shell, that is executed directly in the shell itself.

3
votes
2answers
209 views

Issue with type force PATH search

This is Bash. The behavior is similar in fish. $ which python /usr/bin/python $ alias py=python $ type py py is aliased to `python' ​And then, running type -P py prints nothing, where as I expected ...
3
votes
3answers
243 views

Understanding declare in Bash

After reading ilkkachu's answer to this question I learned on declare (with argument -n) shell built in, help declare brings: Set variable values and attributes. Declare variables and give ...
3
votes
1answer
86 views

Why does `kill` not appear to be a Bash builtin? (it should be) [closed]

The Internet is unanimous: kill is a Bash builtin. Bash changelog says the same. However my other builtins apparently think otherwise: $ builtin kill bash: builtin: kill: not a shell builtin $ type ...
0
votes
2answers
36 views

How can i echo the value of [ 4 -gt 3 ] ,that is a test expression in bash?

How can I echo the value of [ 5 -gt 4 ] ,that is a test expression in bash? [ 5 -gt 4 ] | echo and echo `[ 5 -gt 4 ]` both end up printing a blank line @Thomas Dickey 's answer works but could ...
2
votes
1answer
46 views

Documentation on bash completion

I've been unable to find complete documentation for the complete and compgen bash builtin commands. I'm on a Macintosh and help complete produces complete: complete [-abcdefgjksuv] [-pr] [-o option] ...
18
votes
2answers
1k views

Why does POSIX require certain shell built-ins to have an external implementation?

From this question about whether printf is a built-in for yash, comes this answer that quotes the POSIX standard. The answer points out that the POSIX search sequence is to find an external ...
14
votes
3answers
533 views

Slightly confused about whether printf in the yash shell is a built-in command or not

The yash shell has a printf built-in, according to its manual. However, this is what I see in a yash shell with default configuration: kk@eeyore ~ $ command -v printf /usr/bin/printf kk@eeyore ~ $ ...
1
vote
0answers
27 views

Command to list all reserved words [duplicate]

Is there a command to list all reserved words? I'm aware of resources such as the GNU reserved word index, but what I'm looking for is a command that gives me this information for my shell on the ...
1
vote
3answers
60 views

Shell: only double quote on test -n/-z? [duplicate]

In case of test -e for example: VAR="<this is a file path: /path/to/file/or/dir" test -e $VAR && do_something || do_anotherthing Question: Should I use "$VAR" here?, here I don't like ...
0
votes
1answer
36 views

How can I extract a function from bash/zsh with all its shell-related dependencies?

I write a lot of little useful functions, and sometimes I like to share them with friends or the world. The problem is that I use a lot of my helper functions and aliases in my functions, and I don't ...
1
vote
1answer
596 views

Password Encryption [duplicate]

I have a Migrate.ksh file, in that some passwords are available, I would like to encrypt this file in the Unix. The Passwords file being used in another script. Can you please let me know the process ...
-3
votes
2answers
129 views

rm -rf ./* deletes content of current directory only partially [duplicate]

rm -rf ./* deleted all content of current directory only partially. Input: MN> cd ~/mydir MN> rm -rf ./* MN> ll Output: -rw-r--r-- 1 MN MN 1025 Aug 1 15:50 .file1 -rw-r--r-- 1 MN MN ...
0
votes
1answer
49 views

How bash builtins works with pipeline

Bash builtins defines as: The shell executes the command directly, without invoking another program. And a pipeline like foo | bar works roughly like: bar waits inputs from foo, and foo exits ...
0
votes
1answer
134 views

Does a Linux command called (h) exist?

I read in an unofficial documentation about a Linux shell command called h: it was mentioned together with the help and man commands, without any explanation. So I tried it on my linux terminal but it ...
0
votes
0answers
25 views

send stdin to stderr for a time, then stop after timeout and discard: gnu textutils?

We have a very chatty application which says useful things during startup but then refuses to be quiet (useful logs are sent elsewhere). This interacts problematically with log rotation, snapshotting, ...
-3
votes
1answer
79 views

Does a shell builtin command actually run the program from its path?

I was reading the marked answer from here : What is the difference between a builtin command and one that is not? Here he says : A built-in command is simply a command that the shell carries out ...
-1
votes
2answers
83 views

Wait command works when pid doesn't exists

I'm facing an unexpected behaviour of the wait builtin. ~ ❯ sleep 1 & [1] 72009 ~ ❯ [1] + 72009 done sleep 1 ~ ❯ wait 72009 ~ ❯ echo $? 0 Although the PID doesn't exist anymore wait ...
0
votes
2answers
35 views

getting only the path out of `type -p prog` command

if I run nrolland@mactoasty ~ $ type -p skhd skhd is /usr/local/bin/skhd I can't compose it nicely with other command like nrolland@mactoasty ~ $ la `type -p skhd` ls: is: No such file or ...
9
votes
2answers
1k views

Understanding shell builtin commands

In in the bash manual, it's written that Builtin commands are contained >>> within <<< the shell itself Also, this answer states that A built-in command is simply a command that ...
0
votes
0answers
39 views

checked and silent acquisition of an fd with exec

How can I acquire an fd for reading with Bash so that I can branch on the exit code without any further side effects? This is success and failure without the branch: $ set -u # -ue actually $ exec {...
-4
votes
4answers
180 views

Is there a bash builtin command which can show the environment variables of the current shell?

env and printenv are both external commands i.e. executable files, not bash builtins. The problem with them is that some environment variables (such as _, and I also wonder if there are more) which ...
1
vote
1answer
142 views

How to capture stderr of a bash keyword (e.g. time)?

I want to time reading bash history and put the result into a variable. Unfortunately, time (which is a shell keyword) prints the result to stderr, and apparently redirecting stderr from shell ...
3
votes
1answer
276 views

Need for the `builtin` builtin

What's the point of the builtin builtin when the command builtin has the exact same functionality when it comes to looking up builtins? When making sure that a particular builtin is chosen over a ...
-6
votes
1answer
44 views

`declare` un-causing problems with missing functions/commands?

summary: If in bash I attempt to assign the output of a missing function to a previously-declared (i.e., not {constant, read-only}) variable, I can detect the failure with "normal" tests. But if I ...
1
vote
0answers
63 views

Would a 'function_not_found_handle ()' loadable bash builtin be possible?

I wrote a function to handle unknown commands in bash via command_not_found_handle (). My intention is to source scripts on demand and access its functions inside the handler. But unfortunately the ...
3
votes
1answer
157 views

What do special characters stand for in echo {A..z}

I know we can print a sequence of letters of the Alphabet using echo command and experimented it a little by doing this. Lowercase letter Sequence $ echo {a..z} a b c d e f g h i j k l m n o p q r s ...
1
vote
1answer
220 views

dirs -v does not list the directory stack?

I have seen How do I use pushd and popd commands? , and I am aware that with pushd <dir> I would push <dir> to the directory stack, with popd I would pop the top directory from the ...
-1
votes
1answer
55 views

What is the difference between shell builtins and shell keyboard shortcuts?

What is the difference between shell builtins (like cd or echo) and shell keyboard shortcuts (like ctrl+u or ctrl+l)? Both seems to me "builtins", what is the major difference by means of system ...
1
vote
0answers
27 views

What is the behavior of `command`? [duplicate]

According to this comment which is in defense of the author's answer, @einpoklum Yes, it is necessary. In fact, even this solution may break in one edge case. Thanks for bringing this to my ...
7
votes
2answers
724 views

How to bypass bash functions called `command`, `builtin` and `unset`?

I am aware that aliases can be bypassed by quoting the command itself. However, it seems that if builtin commands are "shadowed" by functions with the same names, there is no way to execute the ...
2
votes
1answer
28 views

Efficient stdin generation in shell script

Is there a more idiomatic way to express the following? xargs -r -l1 -I % bash -c 'cat <(echo %)' Where cat stands for intended program that does not accept relevant argument from command line, ...
0
votes
2answers
179 views

When a shell runs a builtin, and a signal is generated by keyboard, what will handle the signal?

Please correct me if I am wrong: When a bash shell runs an external executable program, the bash shell will create a child process to run the program in foreground. If there is any key-generated ...
-2
votes
1answer
157 views

Shell Script for formatted output [closed]

06/26/2017 23:40:40 CAUAJM_I_10082 [aspsun14 connected for IOALPPRXXBD_ALPGLGENFAALL 55443.15215291.1] 06/26/2017 23:40:40 CAUAJM_I_40245 EVENT: CHANGE_STATUS STATUS: STARTING ...
3
votes
2answers
378 views

How to distinguish between builtin and external util? (e.g. echo)

Some commands are provided as both builtins and external utilities. Take echo for example. On my machine (macOS) running Bash 3.2, $ type echo echo is a shell builtin Running man bash | less --...
1
vote
2answers
153 views

bash custom builtin

I am wanting to build a custom builtin in bash -- like time for example. Is this possible? If it's not, is it possible in another shell? For example, I want to do this: map find -name '*.js' | xargs ...
6
votes
1answer
2k views

What is the parameter “i” of the set command in the bash shell?

I looked up the shell builtin command set by typing help set, and the short syntax description shows: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] The help-documentation explains, ...
20
votes
2answers
4k views

What is the purpose of the bash `suspend` builtin command?

I typed help suspend and got this short explanation: suspend: suspend [-f] Suspend shell execution. Suspend the execution of this shell until it receives a SIGCONT signal. Unless forced, ...
1
vote
0answers
480 views

Why does 'typeset' not work for me but 'declare' does? [closed]

I switched the shell on my main account to zsh and when installing a script that logs history to a database, https://github.com/larkery/zsh-histdb, I saw that some typeset commands in them didn't work,...
1
vote
2answers
858 views

How to specifically run a shell builtin command

Consider a situation that I run these commands in my current shell or I put them inside .bashrc: alias source='echo hi' alias .='echo hi' alias unalias='echo hi' Or function source(){ echo hi; }, ...
44
votes
8answers
4k views

Why are POSIX mandatory utilities not built into the shell?

The purpose of this question is to answer a curiosity, not to solve a particular computing problem. The question is: Why are POSIX mandatory utilities not commonly built into shell implementations? ...
0
votes
1answer
26 views

Unexpected source (mis)behaviour

I have a file with my Raspberry Pi address named pi. It's in my home directory. pi=192.168.0.173 To connect to the Pi, I'd do this in my home directory: . pi && ssh pi@$pi It worked. Then ...
-1
votes
1answer
141 views

Any bash magic to reference the previously typed parameter? [duplicate]

This question is a variant on a previously asked How to repeat currently typed in parameter on bash console? Many a time, I find myself wanting to slightly rename a file name in the shell, e.g.: $ ...
10
votes
1answer
1k views

What is an “s” inside “$-”?

I'm normally well aware of the contents of $-. On a recent CentOS I get: [grochmal@orion ~]$ echo $- himBH hmBH are all options from set, and i means that my shell is interactive. Yet, on my Arch ...
2
votes
1answer
159 views

Why do shells implement their own “echo” commands internally? [duplicate]

(Note that this is entirely an academic question... I'm just curious about the answer, not trying to solve any particular problem.) From the ECHO(1) manual page (GNU echo): NOTE: your shell may ...
-1
votes
1answer
121 views

Redirection in self created linux shell [closed]

I am writing my own shell. I want to implement redirection( > and >>). For that I have used dup2() system call. But if a command I enter has redirection, another command follows the previous ...
2
votes
1answer
340 views

AIX - use ksh builtins to free memory when fork not possible

Context: an AIX lpar with very low memory (no forking possible, so only shell's builtins (cd, echo, kill) will work). I can have a (hmc) console to it, but I need a better way to start freing memory ...
67
votes
4answers
74k views

What's the difference between eval and exec?

eval and exec are both built in commands of bash(1) that execute commands. I also see exec has a few options but is that the only difference? What happens to their context?
9
votes
1answer
1k views

How can I get a help message for zsh builtin's?

If I want to get a brief usage message for a bash builtin, I can use help <builtin> at a command prompt, e.g. $ help export export: export [-fn] [name[=value] ...] or export -p Set export ...
1
vote
0answers
136 views

How to write decorator commands [duplicate]

I don't know the exact word, that's why I'll use "decorator", like in POO, but I'm talking about the kind of functions you can use before other functions to add any operations to it, like the command ...
0
votes
2answers
963 views

How does the shell decide which of same-name keyword, builtin, and external command to run? [duplicate]

When there are same-name builtin, keyword and/or external command, what is the order in which the Bash shell decides which to run? For example, keyword time and external command time, builtin ...