Questions tagged [shell-builtin]

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

0
votes
1answer
36 views

How to know from which bash version a built-in is made available?

Is it possible to know from which specific version of bash a particular built-in is made available from the command-line? Is it only possible by browsing through release notes for each of the versions ...
1
vote
1answer
28 views

How do I return octal from Bash's arithmetic expansion?

As clearly spelled out in the Bash documentation on shell arithmetic, if you prefix a number with a 0 within an arithmetic expansion expression (e.g., $(( expr ))), it's treated as octal. Similarly, ...
0
votes
0answers
36 views

Examples of common programs

Is there a some man-like program (or site/book) that can show me simple examples of common tools usage? So i can type in terminal show-example grep and it will output ... For matching multiple ...
6
votes
3answers
416 views

Shell builtin `printf` line limit?

The /usr/bin/printf util argument list length is limited to the shell's maximum command line length, (i.e. getconf ARG_MAX, on my system that'd be 2097152); example: # try using a list that's way too ...
8
votes
4answers
591 views

Bash Read: Reading comma separated list, last element is missed

The output of the command below is weird to me. Why does it not give me back element 5? $ echo '0,1,2,3,4,5' | while read -d, i; do echo $i; done 0 1 2 3 4 I would expect '5' to be returned as well. ...
2
votes
2answers
65 views

What's the POSIX specification on behavior of built-in commands with redirections and/or piping?

Consider the following commands: exit > /dev/null exit | cat On a few shells (ksh, bash, (d)ash), the behavior is the same: The first command causes the shell to quit immediately, while the ...
3
votes
2answers
211 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 ...
5
votes
3answers
479 views

What is “declare” in Bash?

After reading ilkkachu's answer to this question I learned on the existence of the declare (with argument -n) shell built in. help declare brings: Set variable values and attributes. Declare ...
3
votes
1answer
94 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
42 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
58 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 ...
13
votes
3answers
580 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
39 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
66 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
40 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
776 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
160 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
67 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
146 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, ...
-2
votes
1answer
84 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
128 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
37 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
2k 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 ...
-4
votes
4answers
188 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
181 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
280 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
46 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
71 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
162 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
268 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 ...
6
votes
2answers
776 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
183 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
167 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 ...
2
votes
2answers
405 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
155 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
523 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
905 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
27 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
143 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
163 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
132 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 ...