Questions tagged [dash]

The Dash shell, a POSIX-compliant derivative of the Almquist shell used as /bin/sh in Debian, Ubuntu and other Linux distributions

Filter by
Sorted by
Tagged with
0
votes
1answer
39 views

Dash non-interactive non-login rc file

Does dash have a non-interactive non-login rc file? I've read the man page, which recommends .profile for login shells and $ENV environment variable for interactive shells. Is there anything that ...
1
vote
1answer
69 views

How to kill all background jobs in dash?

Simply kill $( jobs -p ) not work in dash. For example in dash: $ sleep 999 & $ kill $(jobs -p) dash: 2: kill: Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or kill -l [...
2
votes
1answer
30 views

No /var/lib/dpkg/info/dash.preinst in Buster

In https://wiki.debian.org/Multistrap#Steps_for_Squeeze_and_later, it's required to run the following command in chroot environment: /var/lib/dpkg/info/dash.preinst install This command runs in ...
6
votes
2answers
901 views

Are shells allowed to ignore NUL bytes in scripts?

Because that's what some of them are doing. > echo echo Hallo, Baby! | iconv -f utf-8 -t utf-16le > /tmp/hallo > chmod 755 /tmp/hallo > dash /tmp/hallo Hallo, Baby! > bash /tmp/hallo /...
5
votes
2answers
153 views

Is there a way to make the local command work portably to dash ksh bash and zsh?

In dash (and in bash zsh and some other shells) the command local works to make a variable scope limited to that function (and descendants in some cases). That enable the possibility of making a ...
4
votes
2answers
183 views

Why the parent shell here-document not work for sub-command in dash but bash work?

I'm run on debian stretch, all below commands(dash and bash) is input to bash. The whoami seem never run as the user test in dash as in below codes. $ sudo dash << 'end' > su test > ...
2
votes
1answer
106 views

Putting “$@” in a local variable in dash

I have a Bash function that does some string manipulation on its arguments as a whole ("$@") by putting it in a local variable, something like this: #!/bin/sh my_func() { local args="$@" ...
0
votes
3answers
116 views

I would like to check if a file name matches a certain pattern

I would like to check if a file name matches a certain pattern start with an alphanumeric character ([a-zA-Z0-9]) and will only contain alpha-numeric characters plus '.', '-' and '_' characters. ...
4
votes
0answers
112 views

dash not expanding glob wildcards in chroot

I'm working with a copy of Raspbian, installed with pi-gen. Pi-gen runs in a Docker container with a volume for the filesystem, running debootstrap and custom scripts inside a chroot to the volume. I'...
4
votes
3answers
2k views

Why does ''cat "${1:-/dev/stdin} | … &>/dev/null'' work in bash but not dash?

Script: #!/bin/sh # # reads stdin/file and copies it to clipboard # clears it after 30s # cat "${1:-/dev/stdin}" | timeout 30 xclip -i -selection clipboard -r -verbose &>/dev/null & I ...
6
votes
3answers
515 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 ...
1
vote
1answer
149 views

Exit status of chained commands

I want to run a potentially invalid command in a variable cmd. I can't afford to have it just fail me and retrieve the exit status. What I can try to do is pipe it to : and then I'll have a successful ...
0
votes
1answer
37 views

Why can't echo and printf output variables that have only whitespace characters? [duplicate]

var1=$(printf "\n\x0A\n") var2=$(printf "\na\nb\nc") Using Android Terminal, the output of echo -e "$var1" (same for echo and printf) iss nothing, not even the 3 new lines. But echo -e "$var2" or ...
3
votes
1answer
759 views

dash: why am I getting the error “Syntax error: EOF in backquote substitution” when my script doesn't even contain a backquote?

#!/bin/sh -- for set_trap_sig in HUP INT QUIT ALRM TERM; do trap -- ' trap -- - '"${set_trap_sig:?}"' EXIT || exit "$?" kill -s '"${set_trap_sig:?}"' -- "$$" || exit "$?"' "$...
1
vote
1answer
33 views

How to not split words [duplicate]

I have a list of commands in a file called cmds, one command per line. I want to grab the last command, set it in a variable last_command and run it later. with $last_command or "$last_command", or ...
2
votes
2answers
358 views

Using diff to compare the output of two commands

How does one go about using diff to compare the output of two commands? I know how to use it to compare the contents of a file filename1 with the output of a command cmd2: cmd | diff filename - How ...
1
vote
2answers
78 views

Escaping spaces in dash [duplicate]

I want to do something like this. $ touch a\ b $ cmd=cat\ a\ b $ echo $cmd cat a b $cmd cat: a: No such file or directory cat: b: No such file or directory There are problems with the spaces in the ...
5
votes
1answer
123 views

dash maximum variable length under systemd

I have a shell script that uses a single variable as an associative array (one KEY=VALUE per line). Throughout the execution of the script, the variable is manipulated to add, remove or modify ...
0
votes
0answers
231 views

Accessing command history in dash

When I try to run history in dash, I get an error message. This is expected as far as I can tell. When I run fc I too get an error message like "dash fc: not found". So how do I access the command ...
0
votes
0answers
103 views

History not working in a Dash i-shell (with Bash as a parent process)

My terminal initializes with Bash. I run dash and enter an interactive Dash shell. I run a few random commands and try to run history only for it to fail. I check if history is enabled and it ...
2
votes
2answers
46 views

How do ranges in dash work?

I'm trying to figure out how to rush the following bash script in dash. for x in {1..5} do for y in {a..c} do echo $HOME$x$y done done Dash does not support brace expansion and I don'...
4
votes
3answers
552 views

How to escape the null character in here-document?(bash and/or dash)

I want to perform shuf --zero-terminated on multi-line strings with here-document.
5
votes
1answer
929 views

What's going on with this dash '-' thing?

I was trying to export the Python environment requirements and this is what I intended to do: conda list -e > requirements.txt However I mistakenly typed this instead: conda list -e -> ...
2
votes
1answer
111 views

Dash - how to escape strange path characters

If the follow strange directory is created: a"␤ b" In bash or zsh one can do: cd a$'\n'b or cd 'a'$'\n''b' What is the equivalent for dash?
7
votes
4answers
903 views

Portable check empty directory

With Bash and Dash, you can check for an empty directory using just the shell (ignore dotfiles to keep things simple): set * if [ -e "$1" ] then echo 'not empty' else echo 'empty' fi However I ...
1
vote
1answer
277 views

Can't change shell from dash to bash on Linux Mint VM [closed]

Just installed a virtual machine via virtualbox yesterday and I'm having trouble switching the shell from dash to bash. I've tried chsh as well as modifying the file directly, but it still defaults to ...
0
votes
1answer
75 views

Bash command “reset” — dash (sh) equivalent?

When the fonts get messed up in dash (jackpal.androidterm), how do I reset that one? When printing contents of binary files, special characters can mess up the terminal character set. How can this be ...
1
vote
1answer
118 views

some sed commands fail when in background

Some sed commands seem to fail when run in background. Minimal example below. One sed command appends append after a block of lines that begin with a star *. The other just substitutes a word. The ...
6
votes
2answers
121 views

Is it normal that bash stat() and access() much, before commands?

Running strace on the bash shell that is instructed to run mkdir provided this output which shows lots of stats prior to execve the actual mkdir binary: BASH$> strace -f sh -c "bash -c \"mkdir /...
1
vote
2answers
176 views

How to check left command's exit status in pipe “left | right” in dash when left command produces large output

It seems that the variable "PIPESTATUS" is unavailable in dash. Simple separate execution is not working because the left command produces very large output. I used a fifo to do this task: #!/bin/...
1
vote
1answer
447 views

Is there an invoked file for dash and sh as non login shells in /etc directory?

/etc/profile can be invoked by sh and dash inside an interactive login mode. Is there any file in /etc directory to be invoked when they are in an interactive non-login mode?
1
vote
1answer
286 views

Using the 'a' and 'c' options with the 'dash' command in Unix [closed]

What do the options 'a' and 'c' do when there are used with the command 'dash'? I was unable to understand what that command actually does! I have tried reading the man page but didn't exactly ...
1
vote
4answers
2k views

/bin/sh: read variable from pipe [duplicate]

In bash or zsh, I can use following syntax to read from pipe into variables: echo AAA BBB | read X Y ; echo $X which will print AAA Why does the same not work in /bin/sh? I am using /bin/sh -> /...
1
vote
1answer
179 views

How can I set PATH in the `dash`(or bash) shell so that it doesn't search any dirs ? because empty PATH searches current directory

In Dash if I set the PATH to an empty string, it searches in current directory: $ export PATH= $ echo $PATH $ emptyexe $ /usr/bin/ls emptyexe emptyexe $ pwd /home/ctor $ cd .. $ emptyexe dash: 36: ...
0
votes
1answer
42 views

Where is '/?' parameter expansion documented?

I came across this weird parameter expansion for bash/dash which I don't find any reference for. What is this sort of expansion called? Where is it documented? $ /??? bash: /bin: Is a directory $ /???...
1
vote
0answers
335 views

Dash escaping hyphen?

I am using Homebrews dash package on MacOS to print a text. echo "Hello World - Test" But I am receiving Hello World \- Test What am I doing wrong?
0
votes
1answer
77 views

POSIX-ly correct way to isolate files with newlines via find?

There's a question How to find files that contain newline in filename?, where the accepted answer handles isolating files with newlines via ANSI-C quoting, and that works fine in ksh and bash, but how ...
8
votes
1answer
647 views

Is parameter expansion on $@ not supported by the sh shell?

I posted an answer to a question on AU, and I found that parameter expansion on $@ doesn't work with the sh shell: <infile xargs -d'\n' sh -c 'echo "${@%%/*}"' _ but it works fine in bash. Is ...
1
vote
1answer
1k views

BASH/DASH: What is the best way to pass array to function?

I have this array: PARAMETERS_OF_COMPONENTS[1]="component1" PARAMETERS_OF_COMPONENTS[2]="component21 component22 component23" PARAMETERS_OF_COMPONENTS[3]="component3" PARAMETERS_OF_COMPONENTS[4]="...
2
votes
1answer
373 views

Dash “-nt” behavior

The use case I can think of for -nt, would be updating a file if it is too old, or if it does not exist. Bash handles this just fine: $ bash -c 'touch 2.txt; sleep 1; touch 1.txt; [ 1.txt -nt 2.txt ];...
2
votes
1answer
375 views

How do I reliably convert /proc/pid/environ to arguments for the env command?

How do I reliable convert /proc/pid/environ to argument for the env command? IFS=$'\n' ; env -i $(xargs -0n1 -a /proc/$$/environ) only works when all environment variables do not have the newline ...
8
votes
2answers
1k views

Test if variable contains newline (POSIX)

I know that some shells accept this kind of test: t() { [[ $var == *$'\n'* ]] && res=yes || res=no printf '%s ' "$res"; } var='ab cd' t var='abcd' t echo on execution: $ bash ./...
2
votes
1answer
133 views

Does fd number of various shells fixed?

Let's say: xb@dnxb:/tmp$ echo 'ls -l /proc/$$/fd | grep a.sh' > a.sh; \ > while IFS='' read -r f; do \ > echo "$f"; "$f" a.sh; \ > done < <(tail -n +2 /etc/shells) /bin/sh lr-x------...
5
votes
1answer
641 views

Why does CDPATH not work as documented in the manuals?

The Bourne Again shell manual says, of cd dir: […] each directory name in CDPATH is searched for dir. […] If dir begins with a slash (/), then CDPATH is not used. The Z shell manual ...
9
votes
4answers
3k views

Split string on colon in /bin/sh

My dash script takes a parameter in the form of hostname:port, i.e.: myhost:1234 Whereas port is optional, i.e.: myhost I need to read the host and port into separate variables. In the first case, ...
1
vote
1answer
148 views

How to find out the version number of `dash` without resorting to package management systems?

I have been using bash most of the time and has just started playing with other shells. I started with dash and tries to find out its version number but the usual method like -v or $version does not ...
8
votes
1answer
422 views

Why does exiting with a stored returncode of a nested command result in different returncodes in Dash and Bash?

Running bash -c 'bash -c "echo test1; exit 1;" &> /tmp/x; buildresult=$?; tail -n 100 /tmp/x; exit $buildresult;' results in test1 being printed to console and echo $? to print 1 which in my ...
3
votes
1answer
4k views

bash command substitution with redirection: bad file descriptor

the following command works in dash but fails in bash with "Bad file descriptor". $ dash -c 'out=$(echo "to fd3" >&3; echo "to stdout") 3>&1; echo "out: $out"' to fd3 out: to stdout $ ...
0
votes
1answer
765 views

Why is using git with && failing when inside a .sh but not from the command line?

I have a script (called update_content.sh) that is supposed to run 3 consecutive git commands and the first version looked like this: #!/bin/sh git fetch --all && git reset --hard && ...
2
votes
3answers
808 views

Error cleanup for shell scripts

What's the best way to include error cleanup logic for shell scripts? Specifically, I have a script that does something like this: mount a x mount b y setup_thing mount c z do_something umount z ...