Skip to main content
1 vote
1 answer
729 views

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 ...
Timmmm's user avatar
  • 99k
1 vote
0 answers
47 views

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

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 ...
ferdymercury's user avatar
0 votes
1 answer
79 views

Pass the entire content of the variable into a function

I need to convert the contents of the variables as they are into base64. I decided to make a function and pass the content of the variables into it and output it later. So far I have the following #!/...
KarlsD's user avatar
  • 667
1 vote
3 answers
2k views

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 ...
krave's user avatar
  • 1,919
0 votes
1 answer
99 views

How do I pass command-line arguments to script executed from stdin

These work fine: /bin/dash xyz.sh arg1 curl | /bin/dash - Use case: curl | sh - arg1 Ubuntu executes this as: curl | /bin/dash - arg1 this fails with: sh: 0: Can't open arg1 How do I pass arg1 to ...
u15p7fgy863eiq5's user avatar
0 votes
0 answers
300 views

local marked function variables unavailable inside trap function - (d)ash shell

I've read that the local keyword introduces dynamic scoping, meaning the variable defined thus in a function will be visible until the function dies. Hence visible and changeable in other functions ...
ustulation's user avatar
  • 3,840
1 vote
1 answer
116 views

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: kernel/drivers/char/tpm/tpm.ko kernel/...
NewBit's user avatar
  • 145
2 votes
1 answer
544 views

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&...
Ray's user avatar
  • 21
0 votes
1 answer
283 views

Why does "echo" ignore its first argument sometimes?

The output of this code seems to depend on the option I give (-n or -a) but I simply don't understand the reason. Here's the portion of the code that doesn't work (just the code itself + outputs): #!/...
sirakai's user avatar
2 votes
4 answers
1k views

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....
KNOB Personal's user avatar
0 votes
1 answer
410 views

dash script, send yes for a command

I want to call a command with a script using dash. here is my code: #!/bin/sh ip='172.45.0.219' cmd1='yes yes' cmd2="./ssh foo@$ip" eval $cmd1 | $cmd2 when I run my script this is my output:...
R.A.'s user avatar
  • 9
3 votes
1 answer
3k views

"kill %1" fails and prints "No such process" inside script

I am currently using dash as main shell. I tried to write a little function that should imitate wait, but with some text. Here's a minimal, working code: #!/bin/dash wait() { echo Waiting... ...
ingroxd's user avatar
  • 1,071
0 votes
1 answer
609 views

How to close a dd process that was started in a dash script with -SIGINT?

When I start a dd process directly from the Terminal with dd if=/dev/zero of=/dev/null & command, and send to it a -SIGINT with kill -SIGINT <pid> command, it closes successfully. But when ...
Андрій Немченко's user avatar
0 votes
2 answers
389 views

Dash and C: eval "$(<cmdfile)" and system("eval \"\$(<cmdfile)\"") giving different results

I would like to use the system() function in C to evaluate an expression within a file cmdfile but I'm not getting the same results as when I do so on the command line directly. The content of cmdfile ...
borizzzzz's user avatar
  • 630
0 votes
1 answer
551 views

Loop through a list of files with a specific MIME type in sh

I have a directory, and need to get a list of files with MIME types of application/pdf, which I can loop through and process with my CompressPdf function. The remaining files only need to be copied ...
Livy's user avatar
  • 683

15 30 50 per page
1
2 3 4 5
11