shell-builtin

How To Auto `command -p` In All My Script?

How To Auto `command -p` In All My Script? I want to execute all commands within my script with command -p e.g.: command -p pwd Because there may be some command that I will execute within the script whose name is being used by some other custom user script and in this case the command …

Total answers: 2

Is the following `readonly` use POSIX-ly correct?

Is the following `readonly` use POSIX-ly correct? I defined the following as read-only: readonly root_command=’sudo -s’ later used in my script as in: exec $root_command My question is, maybe I am slow or something, but I do not fully understand the POSIX man page, as for example if I can single quote or have to …

Total answers: 1

How to avoid kickout from SSH when script fail

How to avoid kickout from SSH when script fail Please forgive my basic unix/linux scripting skill and poor English I am testing a script in the Linux VM, let’s say it is work.sh. So I have to ssh to the VM ssh myname@theVm.domain.app with my access, then I need to run the script in my …

Total answers: 2

some_variable vs some-variable in zsh

some_variable vs some-variable in zsh Why is it that zsh seems to understand what to do with some_variable=1 command, but not some-variable=1 command? E.g.: $ fs_screen=1 mpv –fs-screen=${fs_screen} someFile.mp4 works fine but $ fs-screen=1 mpv –fs-screen=${fs-screen} someFile.mp4 results in zsh: command not found: fs-screen=1 I went digging through the zsh documentation and found what I …

Total answers: 1

arbitrary base conversion from base 10 using only builtins in bash

arbitrary base conversion from base 10 using only builtins in bash I’m trying to sort out a bash command to convert a number from base 10 to an arbitrary base, using a specified set of characters (for example, to base 26 using letters a-z, although that’s not actually my use-case). I have solved this problem …

Total answers: 3

Problem with bash builtin bind and escaping

Problem with bash builtin bind and escaping I’m trying to add a history fuzzyfind hotkey to my bash shell. However, my intended command gets cut in the middle: [april@Capybara-2:~]$ cat ~/.bashrc bind ""C-r": "$(history | fzf | awk ‘{$1=""; print substr($0,2)}’)"" [april@Capybara-2:~]$ $(history | fzf | awk ‘{$1=""; (The second line is the result when …

Total answers: 1

Why does `print -c` fail, but piping to `column` succeed to print columns?

Why does `print -c` fail, but piping to `column` succeed to print columns? This works: #!/bin/zsh ### List apps ### arch="$(paru –query –quiet –explicit –unrequired)" repos=( $HOME/repos/./* ) npm=( $(npm list –global –parseable) ) box="${(l:20::─:)}" print -l "${arch}" "${box}" "${repos[@]:t}" "${box}" "${npm[@]:1:t}" | column Results: alsa-utils foot libva-utils patch waylock android-tools fuzzel links pdfarranger wine-gecko …

Total answers: 1

How can one modify the named directory hash table by "creating appropriate shell parameters"?

How can one modify the named directory hash table by "creating appropriate shell parameters"? I’m used to add entrys to zshs named driectory hash table, by using hash -d <name>=<value>. Recently, I read the zshbuiltins(1) man page, where I found the following (description of the hash builtin): Normally one would modify these tables by modifying …

Total answers: 2

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

Exporting zsh history separated by ‘’ characters instead of ‘n’ I want to access zsh history with entries separated out by instead of n. The built-in parser can clearly handle multiline entries, because fc 123 brings up an editor with newlines preserved. However, fc -l 123 (which prints to stdout instead of starting an editor) …

Total answers: 2

checkbashisms: what's wrong with `type'?

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 POSIX? But it’s supported by all common shells (i.e. bash, zsh, dash, busybox sh, mksh; even in ksh; maybe just …

Total answers: 3

Is there a command to get builtin commands on zsh?

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. Asked By: testter || Source See info zsh builtins: builtins This associative array gives information about …

Total answers: 1

Can I make cd be local to a function?

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 function? I know I can save the pwd and …

Total answers: 5

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

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 in 10 times? I know …

Total answers: 5

Shell builtin `printf` line limit?

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 long /usr/bin/printf ‘%sn’ $(seq $(( $(getconf ARG_MAX) * 2 ))) | tail -1 Output: bash: /usr/bin/printf: Argument …

Total answers: 3

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

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. …

Total answers: 4

What is "declare" in Bash?

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 variables and give them attributes. If no NAMEs are given, display the attributes and values of all variables. -n … …

Total answers: 5

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

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 implementation of the desired command, and then, if the shell …

Total answers: 4

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

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 regular built-in at /usr/bin/printf Is printf …

Total answers: 2