Questions tagged [shell-builtin]

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

Filter by
Sorted by
Tagged with
3 votes
2 answers
35 views

Exporting zsh history separated by ‘\0’ characters instead of ‘\n’

I want to access zsh history with entries separated out by \0 instead of \n. The built-in parser can clearly handle multiline entries, because fc 123 brings up an editor with newlines preserved. ...
user avatar
  • 133
0 votes
0 answers
67 views

/usr/bin/type vs. bash's built-in type command

I was reading an article on various Linux commands that can show location of programs in the search path, including which, type, and whereis. The article says that type is a built-in bash command, and ...
user avatar
  • 1
0 votes
1 answer
101 views

About Precommand Modifiers in zsh

Background While the zsh documentation (ch 6.2) provides a description for what precommand modifiers can do, it fails to provide examples for each type: -, builtin, command, exec, nocorrect, and ...
user avatar
2 votes
2 answers
118 views

What is the zsh equivalent of "pushd -n" in bash?

I want to push a directory onto the directory stack in order to refer to it using "tilde shorthand" (eg. ~1 refers to the second entry in the directory list), but I don't want to actually ...
user avatar
  • 546
1 vote
1 answer
124 views

Is there a way to print the commands that the shell builtin `source` is calling when sourcing a script? [duplicate]

sh, bash, etc. have a -x flag that will show you each command that is executing in a script. This is handy for debugging. $ sh -x my_script.sh + case $SOMETHING_DIR in + unset ...
user avatar
  • 768
-4 votes
1 answer
619 views

How to resolve this error for 'help' command not found in Kali Linux? [closed]

I know that help is a shell built-in internal command used to find about built in commands such as cd. But it is not working in my Kali Linux terminal in VirtualBox. It is showing the following error: ...
user avatar
  • 1
6 votes
3 answers
983 views

checkbashisms: what's wrong with `type'?

#!/bin/sh foo() { echo "in foo" } type foo checkbashisms.pl obviously does not like type, why? $ checkbashisms.pl foo.sh possible bashism in foo.sh line 7(type): type foo Is it not ...
user avatar
  • 1,273
4 votes
2 answers
425 views

Bash's read builtin errors on a string-based timeout option specification but not an array-based one. Why?

In reading through the source to fff to learn more about Bash programming, I saw a timeout option passed to read as an array here: read "${read_flags[@]}" -srn 1 && key "$REPLY&...
user avatar
  • 143
1 vote
1 answer
106 views

zsh: Halt when command not found

I want to stop the zsh script running when it encounters a command not found error. I know of command_not_found_handler, but this function only allows me to print a message, not halt the parent shell. ...
user avatar
  • 1,295
5 votes
1 answer
178 views

Difference between command `command` vs command `builtin` in Shell Scripting

I understand the command command is specified in the latest POSIX standard and builtin is not. I also realize that both commands are regular builtins (i.e. they can be overwritten by user-defined ...
user avatar
  • 223
2 votes
1 answer
780 views

How to detect EOF on a BASH script's stdin?

I have a bash function inside a script that needs to read data from stdin in fixed size blocks and send those, one at a time, to external programs for further processing. The function itself should ...
user avatar
  • 21
3 votes
1 answer
195 views

Are there any caveats in using shopt -s autocd?

I have recently discovered the feature shopt -s autocd: autocd If set, a command name that is the name of a directory is executed as if it were the ...
user avatar
  • 415
0 votes
1 answer
105 views

What is the intended purpose of the () syntax in a bash function?

I am freshening up my bash skills. I use the term skills very loosely; I've been outta the game a long time. So, as a way to brush up, I decided to code something utilizing bash/zenity/yad. I read man ...
user avatar
6 votes
5 answers
1k views

IFS=',' /usr/bin/read vs IFS=',' read

Context $ bash --version GNU bash, version 4.4.19(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/...
user avatar
  • 61
1 vote
1 answer
607 views

replace space with underscore in expect script

#!/usr/bin/expect -f set cmd "abc def ghi lkj" set log [ expr echo ${cmd// /_} ] I would like to log variable as ghi_lkj first I wast trying to replace all spaces with underscores and then ...
user avatar
  • 83
7 votes
1 answer
676 views

Is there a command to get builtin commands on zsh?

Is there a command to get builtin commands on zsh? For example, it is possible to get all builtin commands with the compgen -b command in the bash shell.
user avatar
  • 1,102
28 votes
5 answers
4k views

Can I make cd be local to a function?

Is it possible to make a function like function doStuffAt { cd $1 # do stuff } but make it so invoking that function doesn't actually change my pwd, it just changes it for duration of the ...
user avatar
  • 439
5 votes
1 answer
269 views

Bash autocomplete: List files and directories from other directory

I wrote a script called prpsls which creates or edits files inside the directory ~/proposals. Now I'm writing the autocomplete script for it, and I'm trying to set it up in a way that, after I hit Tab,...
user avatar
4 votes
1 answer
354 views

zsh: Read from stdin until a string delimiter

I want to read from stdin until a string delimiter MARKER=$'\0'"BRISH_MARKER" is encountered. I tried: ❯ unset br ; print -rn -- hi${MARKER}world | { IFS= read -d "$MARKER" -r ...
user avatar
  • 1,295
0 votes
1 answer
88 views

Bash history wrap around to the earliest, oldest command

How do we have bash history wrap around to the first, oldest command when at the latest, newest command?
user avatar
1 vote
1 answer
242 views

Why print command can not be called with sudo? [duplicate]

% print ok ok % sudo print ok sudo: print: command not found It seems the print are not properly loaded. So what happened and how can I fix it?
user avatar
  • 365
0 votes
1 answer
80 views

Help with .bash program

I need to add a part to a shell script that will count down the number of command line arguments, printing one per second to the screen and reporting how many command line arguments are left (e.g., by ...
user avatar
2 votes
3 answers
221 views

Reversing a file line-wise and character-wise

Input: hello enrico output: ocirne olleh To do this, I can simply tac a file and pipe the output to rev (or the other way around), so one function that does the job is just this: revtac() { tac &...
user avatar
  • 1,012
-1 votes
1 answer
28 views

How to view all the list that can be viewed by update-alternatives?

Tabbing gives me ls data but i want something to be shown like x-session-manager , x-terminal-emulator and so on. How can i get list what can i set?
user avatar
4 votes
2 answers
726 views

Input redirection to for and while

Just out of curiosity, This command works: $ <file cat But neither of these do: $ <file for bash: for: command not found... $ <file while bash: while: command not found... Why is that?
user avatar
0 votes
0 answers
20 views

'compgen' appears to have undocumented parameter '--', can I rely on it being present across systems? [duplicate]

I happen to be on Ubuntu 18.04, with GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu) The output of % compgen -A file -- test-data foobar -- outputs all files/dirs in the current directory ...
user avatar
2 votes
1 answer
653 views

How to build loadable builtins for Bash

As I recently learned, it's possible to dynamically load custom builtins into Bash (see enable in the manual, and this answer). However I'm not sure how to take advantage of this feature. The linked ...
user avatar
  • 1,586
1 vote
2 answers
77 views

issues Debugging cd on custom shell [closed]

I am having issues with my custom shell cd command I created. Right now I am testing the base case where cd is the only argument, when that is the case its suppose to change the default directory to ...
user avatar
-1 votes
1 answer
119 views

Manual entry for history missing... `man history` [duplicate]

I'm trying to figure out what's going on with my history... but I can't find the manual history -h returns nothing man history returns a level 8 history manual, not the bash one we all use.
user avatar
  • 802
2 votes
1 answer
88 views

Why can't I see the manual for > but can see it for [?

I just did man [ and it opened the manual. Then I tried doing man > but I get this error: -bash: syntax error near unexpected token `newline' How is > different from [?
user avatar
  • 124
0 votes
0 answers
48 views

Where is the information of the hash table stored? In other words, where is its database?

The "command hashing system" should store the path of the shell commands somewhere, right ? Is it a database or what? I am wondering where that is. Also, Is it encrypted ? Do we have a way of ...
user avatar
  • 189
2 votes
1 answer
173 views

Use bash builtin `bind` command when starting chroot

I have a chroot and I want the chroot to have its own .inputrc file when it starts, and then run a program. I'm used to starting the chroot with chroot <PATH> <PROGRAM_TO_RUN> so I tried ...
user avatar
  • 745
0 votes
1 answer
188 views

print list of environment variable names (without values)

There is a POSIX version of this question elsewhere; for those that don't want to live in a cave, this is the modern version.
user avatar
  • 240
15 votes
5 answers
3k views

How to run a command 1 out of N times in Bash

I want a way to run a command randomly, say 1 out of 10 times. Is there a builtin or GNU coreutil to do this, ideally something like: chance 10 && do_stuff where do_stuff is only executed 1 ...
user avatar
  • 329
1 vote
0 answers
242 views

What is the difference between test, [, and [[ in terms of binary vs. builtin? [duplicate]

It is often written: /usr/bin/test is a synonym for /usr/bin/[ [[ is a bash improvement for [ test and [ are also builtins I understand the difference between [ and [[ but I am confused with the ...
user avatar
0 votes
2 answers
140 views

Why does the command 'source' have that name?

I wonder why a command that executes commands from a file in the current shell is named source. I can't see a relation between run commands in the current shell and the meaning of the english word ...
user avatar
  • 143
0 votes
1 answer
228 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 ...
user avatar
  • 11.8k
1 vote
1 answer
481 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, ...
user avatar
0 votes
0 answers
43 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 ...
user avatar
6 votes
3 answers
1k 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 ...
user avatar
  • 6,746
8 votes
4 answers
5k 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. ...
user avatar
  • 1,358
5 votes
2 answers
562 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 ...
user avatar
  • 2,902
3 votes
2 answers
228 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 ...
user avatar
  • 167
29 votes
4 answers
21k 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 ...
user avatar
3 votes
1 answer
495 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 ...
user avatar
  • 386
0 votes
2 answers
982 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 ...
user avatar
2 votes
1 answer
184 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] ...
user avatar
  • 123
24 votes
4 answers
2k 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 ...
user avatar
  • 527
15 votes
2 answers
1k 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: $ command -v printf /usr/bin/printf $ type printf printf: a ...
user avatar
  • 271k
1 vote
3 answers
607 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 ...
user avatar
  • 1,655