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
1 answer
70 views

dash script replace array

This script works if I use bash on my Debian 11 (bullseye). But now I need to refactor it to use Debian's sh shell(/bin/dash). #!/bin/dash var1=1 var2=2 var3=3 arr=($var1 $var2 $var3) exist_var=&...
tuytuy20's user avatar
7 votes
2 answers
1k views

How do I keep a dash shell script running despite any error?

I have a dash shell script that is intended to run to the end of file: #!/usr/bin/dash # File b_shell . a_nonexistent_file echo "I want to print this line despite any previous error." ...
zanetu's user avatar
  • 171
2 votes
1 answer
63 views

How to add a substring to a string as a column

The title may not be the best at describing the issue, but this was the best I could come up with, moving on to describe what I'm trying to do, I use artix runit as my os, and it is tedious to create ...
Stagnant's user avatar
1 vote
0 answers
47 views

Anyway to bind keyboard to dash (Debian Almquist Shell)?

Specifically Up/Down for history navigation. What I already know I understand dash is a minimalistic, no bloat, (somewhat) strict POSIX shell. I understand the philosophy behind it, and the reason ...
Lockszmith's user avatar
3 votes
1 answer
396 views

Why is "${1-"$var"}" (option 6 down below) not mentioned in POSIX?

The only reference I could find in the spec is this: It would be desirable to include the statement "The characters from an enclosed "${" to the matching '}' shall not be affected by ...
QuartzCristal's user avatar
3 votes
1 answer
479 views

Debian /bin/sh in a Docker container never seems to look at .profile

I can not seem to get dash to look at $HOME/.profile: pedz@Peace:s001 ~[S:hatred] % docker exec -it hatred-web-1 dash -i # cat $HOME/.profile PROOF=true; export PROOF PATH=/hatred/bin:$PATH; export ...
pedz's user avatar
  • 173
1 vote
1 answer
994 views

Multiple commands in variable? [duplicate]

Is it possible to execute multiple commands stored in a variable? Singe command works fine variable="echo HELLO" $variable HELLO I would like to have something like this variable="...
user avatar
7 votes
2 answers
590 views

Is there a pipefail equivalent for dash?

I have a perl script that runs a system() call to execute shell commands and I would like to run more than one command and pipe data between them. Something like (in perl): system("command1 | ...
terdon's user avatar
  • 235k
7 votes
1 answer
1k views

Why doesn't sudo always spawn a shell sub-process?

I am trying to understand why some shells seem to receive a special treatment when called with sudo. For instance, there seem to be two possible behaviours: The "implicit" group (pstree is a ...
mesr's user avatar
  • 167
1 vote
1 answer
316 views

Bash for every x files create sub folder and move files there

I am looking for an alternative dash command I can use as I am trying to execute the code from within python and due to the fact that the sub folder has 100's of files I am am trying to group into ...
jessyjack's user avatar
2 votes
0 answers
233 views

how to close file descriptor bigger then 9 by dash in shell script

I want launch a shell script in code called system("sh example.sh"), and close all file descriptors like this: for fd in $(ls /proc/$$/fd); do case "$fd" in 0|1|2) ;;...
meilin's user avatar
  • 21
0 votes
2 answers
889 views

Sourcing file in dash with . file gives "not found" error

I'm trying to source (bash-parlance) a file in dash using . file as specified by the man page: . file The commands in the specified file are read and executed by the shell. But I ...
cheersmate's user avatar
7 votes
1 answer
453 views

What parts of dash are not part of the POSIX standard?

I know that dash adheres quite closely to the POSIX standard, but I know that it's not 100.00% strict POSIX without any extras. The shell that comes closest/adheres exactly to the POSIX standard is as ...
timowhatsoever's user avatar
1 vote
1 answer
314 views

SHELLOPTS equivalent for /bin/dash

I have to run a number of shell scripts that are defined by a third party. So I cannot (or would prefer not to) change their content or which shell (bash vs. dash) they are using. They may or may not ...
Christopher's user avatar
0 votes
1 answer
105 views

Incorrect order of commands in "Command Substitution" (Bash/Dash)

Why is it that when you run the substitution commands, the order of execution is broken, as in the example below. First the chmod command was executed, then echo 1 and echo 2? echo $(echo 1; echo 2; ...
NewLinux's user avatar
  • 147
0 votes
0 answers
52 views

Secure transfer of arguments to a program (dash/bash)

Transfer via stdin #!/bin/dash echo 'password' | program - Transfer via stdin using an intermediate variable var_pass=$(echo 'password') echo $var_pass | program - unset var_pass Transfer via ...
NewLinux's user avatar
  • 147
1 vote
1 answer
222 views

Proper way to wrap dash using rlwrap

On Ubuntu, I have set alias sh='rlwrap --complete-filenames sh' to get readline keybindings and filename completion when using the dash shell (on my computer, sh is /usr/bin/sh, which is a symbolic ...
Flux's user avatar
  • 2,566
-1 votes
3 answers
88 views

Changing the place operator in a csv file

I've been editing a CSV file so I can import it into postgres. At this point I want to change the operator from column 5 to the left side of the column when the value is negative"-". When it ...
matheus soares's user avatar
0 votes
3 answers
78 views

find/detect file name goups

On fs i have files like: PREFIX_GROUPNAME_OTHERNAMES[.txt|.*] eg: A_ABC_A.txt A_ABC_B.txt A_ABC_C.txt A_XYZ_A.txt A_XYZ_B.txt A_XYZ_C.txt For some futher tasks i want to get the group names. $# ...
f b's user avatar
  • 13
2 votes
0 answers
120 views

Can't grep or word count the output of jobs command in dash

This is what I tested in Arch's dash shell and FreeBSD's default sh shell, the results are the same. $ sleep 100 & $ jobs [1] + Running sleep 100 $ jobs | wc 0 0 ...
Lu Xu's user avatar
  • 121
0 votes
1 answer
201 views

purpose of dashes in `wget -qO- https://get.speedify.com | bash -`

In this command: wget -qO- https://get.speedify.com | bash - Source: https://support.speedify.com/article/562-install-speedify-linux ...the first -q is the option for "quiet" mode. What is ...
Gabriel Staples's user avatar
1 vote
1 answer
2k views

ssh: force different shell for non-interactive command execution

how can I force specific shell to be used for non-interactive command execution via ssh on remote server? My default shell on the remote server is zsh, but I need to execute given command using /bin/...
Martin Vegter's user avatar
5 votes
1 answer
1k views

/bin/sh: wildcard expansion does not work in script

I am using dash as /bin/sh. In my script, I have following line: SSH_AUTH_SOCK=/tmp/ssh-????????????/agent.* Which is supposed to match file /tmp/ssh-abcdefghijkl/agent.1234. Even when the file ...
Martin Vegter's user avatar
0 votes
2 answers
415 views

How to execute a one-line posix dash command within dash script to enable coredump?

For unrelated purposes I am forced to produce a script that only works with posix sh. Within my script I have checked if the system allows the creation of coredumps, then if the limit is set to 0 I ...
greenslumber's user avatar
3 votes
1 answer
93 views

dash and local keyword not resetting shell

dash shell (unlike bash and busybox ash implementation where both examples print foo: '') takes value of previously defined variable, i.e. guarding with local does not work: $ foo=ee; bar() { local ...
pevik's user avatar
  • 1,397
-1 votes
1 answer
310 views

Having an interactive shell experience but running everything through dash

So i'm starting to get addicted to POSIX standards and simplicity yet i hate not having autocomplete using the arrows to go through characters and i want a cool shell prompt. so is there anyway that i ...
Imeguras's user avatar
  • 133
0 votes
0 answers
161 views

Why integer division is faster than bitwise shift in shell?

I'm comparing performance of bash and dash (default sh in Xubuntu 18.04). I expect sh to be faster than bash I expect bitwise shift to be faster than division operator. However, I'm getting ...
Zeta.Investigator's user avatar
1 vote
2 answers
152 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 ...
henriquehbr's user avatar
-4 votes
1 answer
2k 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 ...
user avatar
0 votes
1 answer
345 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 ...
Lampros's user avatar
  • 143
0 votes
1 answer
153 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 ...
henriquehbr's user avatar
12 votes
2 answers
4k 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 (...
vitalstatistix's user avatar
5 votes
2 answers
922 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" ...
ZiGi's user avatar
  • 53
2 votes
2 answers
1k 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(...
oligofren's user avatar
  • 1,090
1 vote
1 answer
148 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 <&...
ofo's user avatar
  • 121
3 votes
2 answers
595 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....
Murphy's user avatar
  • 41
-1 votes
1 answer
541 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 [ $...
user avatar
0 votes
1 answer
198 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 <...
HappyFace's user avatar
  • 1,493
0 votes
1 answer
301 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` ... ...
alecxs's user avatar
  • 554
2 votes
1 answer
165 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/...
Martin Vegter's user avatar
2 votes
0 answers
353 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' ...
Ilias Karim's user avatar
2 votes
1 answer
955 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 ...
zrajm's user avatar
  • 865
0 votes
1 answer
89 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.
HappyFace's user avatar
  • 1,493
0 votes
2 answers
219 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 ...
Connor's user avatar
  • 31
9 votes
1 answer
7k 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 ...
finefoot's user avatar
  • 2,980
2 votes
2 answers
2k 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 ...
finefoot's user avatar
  • 2,980
1 vote
1 answer
846 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 ...
Nick Bull's user avatar
  • 553
1 vote
1 answer
739 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 [...
illiterate's user avatar
2 votes
1 answer
211 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 ...
ceremcem's user avatar
  • 2,251
6 votes
2 answers
1k 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 /...
user avatar