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
1
vote
2answers
55 views

Can't delete multiple files with spaces on name with rm

I'm working on a deploy script for my dotfiles, they are stored on a Git bare repository, from which i git checkout it's files into my home directory, in order to seamlessy do it without thousands of ...
-4
votes
1answer
66 views

How to printf ascii characters with hex or dec inside /bin/sh -c '…'?

/bin/sh would be dash what is the correct syntax for printf to display certain ascii character using hex or dex code in dash? let's say i want to printf a dollar sign ($). which hex or dec code should ...
0
votes
1answer
34 views

Global Variables across scripts [duplicate]

Why is lets say HOME recognized by all my scripts but my variable DMENU isn't? I export it in my bspwmrc file which is executed at start up.Also had it in my zshrc. Why do this? DMENU="-h 27 -z ...
0
votes
1answer
14 views

su not working inside arch-chroot with dash shell

When i try to do the following inside a dash script: #!/bin/dash arch-chroot /mnt /bin/dash <<- EOF su myuser whoami EOF It simply logs the "root", but when i try to do it ...
10
votes
2answers
420 views

Shell script returns 0 exit_status despite syntax error

Consider this script: #!/bin/sh foo=1 if [[ ! -z $foo ]]; then echo abc fi It's using the Bash syntax [[ ... ]] which doesn't work (as expected) when I run it with the default shell on Ubuntu (...
2
votes
2answers
53 views

bash -e and && evaluation inside functions

I'm puzzled by bash (and dash) behavior when -e option is set. Simple example: #!/bin/bash -e func() { false && true } false && true echo "1" func echo "2" ...
1
vote
2answers
69 views

/bin/sh evaluates string while Bash does not

When running the script below, I get two different outputs, depending on whether or not the shell used is sh or bash: regex(){ echo 's/\(.* \)\(!\{0,1\}\)has(/\1\2MOCK_has(/g' } replace_builtins(...
1
vote
1answer
43 views

Can't use variables while feeding commands to bash through stdin

I need to run a small shell script using C popen call (which calls sh -c '<command>'). I can't get my script to work. I isolated the issue to this snippet: #!/bin/bash sh -c 'bash -xev -s <&...
3
votes
2answers
184 views

Why does printf byte formatting fail when executed under `dash`?

The ASCII hex code for a zero is 0x30. Hence, you can print a zero by doing printf '\x30', and it will print a zero. If you put this into a shell script called myScript.sh, and then execute ./myScript....
-1
votes
1answer
71 views

variable regex test in dash?

I got plenty possible variables in a form of [a-z][0-9], eg 1 letter and 1 number. Is there a way to test them in dash? Something like: myvar=o7 if [ $myvar=o[0-4] ]; then "do this" elif [ $...
0
votes
1answer
35 views

dash: How can I quote the arguments ala “${(q+@)@}” in zsh?

I want to quote the arguments in dash (or sh, or even bash if that's not possible). I can do that with "${(q+@)@}" in zsh, such that reval <sth> ... is the same as just typing in <...
0
votes
1answer
51 views

cmd nested in backticks processed from sudo?

Are nested `commands` using (deprecated) backticks executed with root permissions (from sudo command line) while command substitution $(...) is not? for example sudo mount `blkid -u /dev/sda1` ... ...
2
votes
1answer
50 views

emulate zsh multios in dash (multiple redirections)

in zsh, when the option multios is enabled, I can pipe output to two different processes, ie: cat /dev/sda > sda.img | sha256sum > sda.img.sha256 How could I achieve the same in dash, ie /bin/...
1
vote
0answers
92 views

Trap on DEBUG signal for the ash and dash shells?

With the bash shell, you can install a trap on the synthetic DEBUG signal. This is useful and will execute your function or bit of code on every shell command. Not so in ash or dash. $ trap 'echo hi' ...
1
vote
1answer
174 views

Do all POSIX shells implement arithmetic expansion $((…)) in the same way? [duplicate]

I'm trying to write a shell script which should work under any POSIX shell, and I found what seems to be an odd quirk of dash. I'm wondering whether this is something I can rely on working under other ...
0
votes
1answer
27 views

dash: echo args exactly with no processing

I want to do sth like zsh's print -r -- ... which just echoes the arguments without changing them at all. printf -- still interprets directives.
-2
votes
2answers
75 views

execlp() system call

I want to call the ulimit shell command through a C program. right now, I have: execlp("ulimit", "ulimit", "-u", "%d", ulimit_a); It compiles fine, but does not actually edit the user-id max ...
5
votes
1answer
2k views

Error sh: 1: read: arg count

I want to simply wait for the user to acknowledge a message by pressing Return. In bash, I am able to call $ read $ However, in sh (dash in my case), I get $ read sh: 1: read: arg count $ It ...
1
vote
0answers
19 views

length of the command line buffer [duplicate]

Which's the length of the command line buffer, per shell... and per operating system (if applicable)? Mostly interested in contemporary versions of Dash and Bash and Debian and macOS, but if anyone ...
2
votes
2answers
449 views

Why does SIGTERM work to terminate bash but not ash or dash?

Comparing bash, ash and dash, only bash can be terminated by SIGTERM kill -TERM <pid> For ash and bash, I need SIGHUP or SIGKILL kill -HUP <pid> kill -KILL <pid> What's the ...
0
votes
1answer
251 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
337 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
89 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
999 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
399 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
267 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 > ...
3
votes
1answer
343 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
2k 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. ...
8
votes
2answers
417 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'...
5
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
943 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
509 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
81 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
3k 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
35 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 ...
3
votes
2answers
755 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
383 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
248 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 ...
2
votes
2answers
178 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
833 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
932 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
520 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?
8
votes
5answers
2k 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
519 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
99 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
237 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
185 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
351 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
1k 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
409 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 ...