Questions tagged [dash-shell]

A POSIX-compliant shell implementation that aims to be as small as possible. Please use the [hyphen] tag instead of [dash] if your question is about the "-" character.

The Debian Almquist shell (dash), a modern replacement for , is a POSIX-compliant Unix shell. It requires less disk space than , for example, but it is also less feature-rich.

Resources

151 questions
2
votes
1 answer

shell script: `[[` not working as expected

I have a script: ENABLE_SYSLOG=true test -r /etc/default/inotifywait && . /etc/default/inotifywait || exit 99 test -d $INOTIFY_FOLDER || exit 100 inotifywait -mrq -e ATTRIB --format '%w%f' "$INOTIFY_FOLDER" | while IFS= read -r FILE do if [ -f…
vskubriev
  • 826
  • 1
  • 11
  • 21
2
votes
1 answer

Dash -x fails with Bad substitution error

I'm trying to learn how to write portable shell scripts, to do so I'm starting to migrating my personal utilities from bash to sh (dash on my system). There is however a error I'm getting in all cases when I try to run the scripts in debugging mode…
Javier López
  • 823
  • 8
  • 14
2
votes
1 answer

How to assign multiple variables by function return value in dash shell

I use brand new usage of 'bash'. func(){ echo Dan 38 } read name age < <(func) echo "name=$name age=$age" How to convert these into dash? (In fact it is busybox's shell) I use following lines to replace read name age < <(func) func >…
Daniel YC Lin
  • 15,050
  • 18
  • 63
  • 96
2
votes
3 answers

How to change shell to dash from bash

I want to execute some scripts on dash shell compared to standard default bash. This is an example (test.sh) #!/bin/dash echo $SHELL echo $0 This execution gives me /bin/bash ./test.sh as output. I was expecting '/bin/dash' as output. If this is…
marc
  • 949
  • 14
  • 33
2
votes
4 answers

shell - Characters contained in both strings - edited

I want to compare two string variables and print the characters that are the same for both. I'm not really sure how to do this, I was thinking of using comm or diff but I'm not really sure the right parameters to print only matching characters. also…
Mike Weber
  • 179
  • 1
  • 1
  • 10
1
vote
1 answer

Portable way to check if an environment variable is set

In Bash you can check if an environment variable is set with test -v FOO. It doesn't work in Dash on Debian 11 though because its test doesn't support -v: # test -v FOO dash: 2: test: -v: unexpected operator Is there a portable way that works in…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
1
vote
0 answers

how to get the Unix shell executable name for a script marked as executable and bin/bash shebang

I use the function getTrueShellExeName() posted by mklement0 at https://stackoverflow.com/a/23011530/7471760 in order to get the shell name of a script. This works perfectly well in most cases, but I have come to a situation involving executable…
ferdymercury
  • 698
  • 4
  • 15
1
vote
3 answers

How to understand syntax used in "while sleep 1000; do :; done" for dash?

I see this line of script from this tutorial on VS Code doc. while sleep 1000; do :; done I know the functionality of this line is to prevent process exiting. But I don't understand the syntax. Could you please help to explain the script? Do you…
krave
  • 1,629
  • 4
  • 17
  • 36
1
vote
1 answer

How to use SED to find multiple paths in the same line and replace them with a different path?

I have a file with multiple paths in the same line: cat modules.dep kernel/mm/zsmalloc.ko: kernel/crypto/lzo.ko: kernel/drivers/char/tpm/tpm_vtpm_proxy.ko:…
NewBit
  • 115
  • 5
1
vote
1 answer

How to manipulate filenames with whitespace using IFS in dash shell?

I try to print and manipulate all filenames in current directory and there are some filenames containing whitespace. But when I use IFS=$'\n’ to delimite filenames, it also remove character "n" from filenames. Here is my…
Ray
  • 11
  • 1
1
vote
4 answers

How can I multiply a character or string in native POSIX shell script?

This is not a duplicate of the other question for two reasons. That question did not specify that the answer had to be POSIX. The marked answer for that question does not run correctly in a Dash shell. (I don't know how to tell if the answer is…
KNOB Personal
  • 333
  • 4
  • 15
1
vote
2 answers

The scope of local variables in sh

I've got quite a lot of headaches trying to debug my recursive function. It turns out that Dash interprets local variables strangely. Consider the following snippet: iteration=0; MyFunction() { local my_variable; iteration=$(($iteration +…
Livy
  • 631
  • 4
  • 15
1
vote
1 answer

explicit posix mode in dash

I usually work on CentOS 7 and a standard(?, /bin/sh automatically installed) shell handles an option set -o posix. but the option does not work a shell (/bin/sh) in Xubuntu. It says "no such option: posix", when I try set -o posix. What is the…
kensuke1984
  • 949
  • 1
  • 11
  • 21
1
vote
2 answers

Missing "))" in shell script

I'm really sorry I'm a total noob in shell scripting, I looked on the Internet and I didn't find the answer => /home/bee/Scripts/chkbsh: 11: /home/bee/Scripts/chkbsh: Syntax error: Missing '))' #!/bin/sh for file in $((gawk '/^#!.*(…
inanmb
  • 15
  • 2
1
vote
1 answer

Returning true from a shell pipeline

I'd like to conditionally execute a command in a gnu makefile, based on the return value of another command. To be specific, something like this: lsmod | grep -q pfc && sudo rmmod pfc If the current list of modules as output by lsmod contains pfc,…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386