Stack Exchange Network

Stack Exchange network consists of 174 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

Questions tagged [shell-builtin]

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

-2
votes
2answers
55 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
34 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 ...
-1
votes
1answer
108 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
23 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
49 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
37 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
31 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
912 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
20 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
152 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
74 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
265 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
41 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
141 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
91 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
53 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
26 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
523 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
27 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
110 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
139 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
301 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
125 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
1k 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, ...
19
votes
2answers
3k 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
359 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
641 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
24 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
119 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
127 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
83 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
224 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 ...
61
votes
4answers
55k 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?
8
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
71 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
766 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 ...
12
votes
4answers
1k views

Use case / practical example for Bash' builtin exec

Consider this from the documentation of Bash' builtin exec: exec replaces the shell without creating a new process Please provide a use case / practical example. I don’t understand how this makes ...
0
votes
1answer
65 views

How do I execute command to avoid interference from the shell [duplicate]

Sometimes a same command is provided by shell-builtin as well as other file/package. Example: $ type -a printf kill printf is a shell builtin printf is /usr/bin/printf kill is a shell builtin kill is ...
17
votes
5answers
2k views

Write output of `time` in a file, why are parentheses needed?

time writes to stderr, so one would assume that adding 2>&1 to the command line should route its output to stdout. But this does not work: test@debian:~$ cat file one two three four test@...
3
votes
2answers
103 views

Why builtin times doesn't work in pipeline?

I've the following sample script: #!/usr/bin/env bash sleep 5 printf "times cmd: " times printf "pipeline: " times | ( read user sys; echo $user; ) printf "head: " times | head -n1 printf "times cmd ...
11
votes
2answers
1k views

What does “is hashed” mean when using the type command? [duplicate]

I was reading this post and trying out all of the commands in the first answer... I don't really have anything else better to do right now. Anyways, I ran through them all in regards to rm. What ...
0
votes
1answer
204 views

Whatis command (shell builtin vs executable programs)

I know that whatis command is used to output a brief description about an executable program (Command). So both whatis cd whatis type Will print: nothing appropriate (Because from my ...
3
votes
2answers
1k views

The type command can't distinguish between an executable command and a shell script

So I was reading the book The Linux Command Line, and it says that commands are of four types: (1) executable programs (2) shell builtins (3) shell functions (shell scripts) (4) ...
5
votes
1answer
1k views

How to read the man page for a bash builtin? [duplicate]

So, I needed to figure out how "exec" works. However, doing man exec brings me to a 99% useless man page describing what bash builtins are. It of course also does this with many other man pages such ...
10
votes
4answers
1k views

Why is my program called “set” not being executed?

I've created a simple C program like so: int main(int argc, char *argv[]) { if (argc != 5) { fputs("Not enough arguments!\n", stderr); exit(EXIT_FAILURE); } And I have my PATH ...
1
vote
0answers
265 views

When using linux acl mkdir and mkdir -p do different things

I have a directory bar: # file: bar/ # owner: root # group: root user::rwx user:little-jonny:rwx group::r-x mask::rwx other::r-x default:user::rwx default:user:little-jonny:rwx default:group::r-x ...
17
votes
6answers
2k views

Use system command instead of Bash builtin without specifying the full path

I use Bash as my interactive shell and I was wondering if there was an easy way to get Bash to run a system command instead of a shell builtin command in the case where they both share the same name. ...