Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

7
votes
3answers
323 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
42 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 ...
-1
votes
1answer
44 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 ...
0
votes
1answer
54 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
58 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
89 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/...
0
votes
1answer
62 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
63 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
90 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
49 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
36 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
56 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
41 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 ...
7
votes
1answer
443 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
393 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
111 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 ];...
1
vote
1answer
212 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 ...
7
votes
2answers
759 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 ./...
3
votes
1answer
111 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------...
4
votes
1answer
344 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
2k 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
74 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
390 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 ...
4
votes
1answer
2k 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
303 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 && ...
1
vote
3answers
475 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 ...
8
votes
2answers
954 views

How does bash file redirection to standard in differ from shell (`sh`) on Linux?

I wrote a script which switches users while running, and executed it using file redirection to standard in. So user-switch.sh is... #!/bin/bash whoami sudo su -l root whoami And running it with ...
0
votes
3answers
121 views

Why does read -r eat text? [duplicate]

I have a names.txt file with with the top line of text being 51 Pipe-line\Closed3\00001011_-_Portfolio\UW\Old\NID50_Future_022814.xlsx I would like to write new filenames replacing \ with / I wrote ...
0
votes
1answer
171 views

Going through 2D array

I have an expression ls -l `find . -type f` | tr -s [:space:] | cut -d ' ' -f 5 | sort | uniq -c | tr -s [:space:] | sort -k 2n which creates a 2D array like: xx yy xx yy xx yy where xx is ...
5
votes
1answer
219 views

dash: How to capture output of trap (invoked w/o arguments)?

The section on trap in the dash manpage states the following: trap without any arguments cause it to write a list of signals and their associated action to the standard output in a format that is ...
3
votes
1answer
141 views

dash: List declared functions

What is the dash equivalent to bash's: compgen -A function which lists the names of the declared functions.
6
votes
2answers
281 views

dash: Pipe STDIN to multiple commands and their output to STDOUT in defined order

At first I thought this answer was the solution, but now I think I need a temporary file as buffer. This works unreliably: #!/bin/sh echo 'OK' | { { tee /dev/fd/3 | head --bytes=1 >&...
6
votes
1answer
2k views

Assign file name to a variable using pathname expansion

Is there a reliable way to assign a file name to a variable taking advantage of pathname expansion? This works but looks kind of dodgy: the_file="$(echo ~/downloads/stack-*-linux-x86_64-static.tar....
1
vote
3answers
3k views

Print variable with backslashes in dash

My shell is dash. My problem is the following: # A="abc\nde fg" # printf "$A" abc de fg# # B="abc\\nde fg" # printf "$B" abc de fg# # C="abc\\\nde fg" # printf "$C" abc\nde fg# The string ...
0
votes
2answers
1k views

Setting umask for su user command

In my system I set the umask for the user root to 0077 and for the non-root users to 0027 (via /etc/profile). This is working for the normal terminal logins. But if I login as root and change user ...
7
votes
2answers
251 views

Why does dash expand \\\\ differently to bash?

I have a little open source project that for various reasons I've tried to write in reasonably portable shell script. Its automated integration tests check that hostile characters in path expressions ...
12
votes
2answers
819 views

Separate namespaces for functions and variables in POSIX shells

In dash, functions and variables appear to live in separate namespaces: fn(){ fn="hello world" } fn; echo "The value is $fn!" #prints: The value is hello world! fn; echo "The value is $fn!" #...
11
votes
1answer
594 views

how to emulate Process substitution in Dash

In bash, I can use process substitution and treat output of a process as if it was a file saved on disk: $ echo <(ls) /dev/fd/63 $ ls -lAhF <(ls) lr-x------ 1 root root 64 Sep 17 12:55 /dev/fd/...
1
vote
2answers
822 views

How to run a bash script from a sh(dash) script?

I have a sh (shebang #!/bin/sh) script (sh.sh) which invokes a bash (shebang #!/bin/bash) sub-script: . "some-path/bash.sh" In the bash script I have a declaration of an associative array: declare -...
2
votes
1answer
88 views

shell script echo text name in for looping multiple texts

I am trying to do this text1="word1 word2 word3" text2="word4 word5" text1="word6 word7 word8" for var in $text1 $text2 $text3 do echo $var" in "(__?__) done expected output word1 in text1 word2 ...
3
votes
1answer
500 views

Getting script's real absolute path in /bin/sh

I'm looking for a way to get the real absolute path to the current /bin/sh script. It should work for situations like this one: /path/to/symlink/in/PATH/somescript -> ../../Package/current/...
3
votes
2answers
153 views

Job control in dash

I don't understand the problem about which the standard shell in Debian (dash) complains: test@debian:~$ sh $ man ls ctrl+Z [1] + Stopped man ls $ jobs [1] + Stopped ...
4
votes
2answers
345 views

Why does bash 4.3 keep allocating memory in a script

Why does this shell script gradually consume more memory in bash? I’m not using any local variables and although the value of cpid is changing at every iteration because ls exits immediately, but it ...
2
votes
3answers
2k views

How can I access the history buffer in sh? (not in Bash)

Is there a command history in sh, for example how to access it, and as well, how to ensure it is clear? To clarify shells here: let's say you've logged on to a non-Gui Linux system, and $SHELL is ...
0
votes
0answers
100 views

How to freeze the dash bar in Gnome 3?

I'm on a freshly installed Debian 8.3 (Gnome 3.14) and I can't find if it is possible to display the dash bar permanently (as a dock on Mac OS X). The dash is hiding automatically... This looks like a ...
4
votes
2answers
1k views

Running source command with -x for debugging

I am trying to understand how a shell script is working. The tutorial states that the script should be run as the following way: source oe-init-build-env rpi-build Usually when doing this kind of ...
0
votes
1answer
116 views

Dash print expanded commands

Running xtrace or set -x with Bash will print the expanded command: $ bash -xc 'touch "alfa bravo"' + touch 'alfa bravo' However Dash does not print the command that is actually run: $ dash -xc '...
1
vote
1answer
347 views

Bash FUNCNAME equivalent in Dash

Bash can print the current function name: $ bash -c 'g(){ echo $FUNCNAME; }; g' g However Dash cannot use FUNCNAME: $ dash -c 'g(){ echo $FUNCNAME; }; g' It is possible to access the current ...
0
votes
3answers
80 views

DASH scripting errors: I don't think I know how to set up variables correctly

#!/bin/sh export $REG=0x000000 export $DONE=0x4A9FFF while $REG -le $DONE do (($REG+1)) printf 'wm8280_reg get 0x'$REG'\r\n' sleep 1 done This leads to the errors: ./...
1
vote
1answer
27 views

swap windows with dash script

I have written a bunch of dash scripts that resize and move windows for better efficiency. The structure is the following: i have a row of 8 windows that are stacked to the bottom of my screen, like ...