dash-shell

Kill background process on SIGINT

一笑奈何 提交于 2020-01-17 05:49:41
问题 I have this script, which should start a keep-alive script and Sublime Text 3 under Bash for Windows: #!/bin/dash set -e # Keep alive (in background) tail -f /dev/null & pid=$! echo "tail process id: ${pid}" echo "Keep-alive process started with Sublime Text 3\nPress SIGINT (CTRL+C) to kill it..." # Start Sublime Text 3 DISPLAY=localhost:0 /usr/bin/sublime # http://stackoverflow.com/a/19274804/1442219 trap "kill ${pid}; exit 1" INT wait This code generates: tail process id: 49 Keep-alive

List currently defined functions in dash?

試著忘記壹切 提交于 2020-01-02 08:19:11
问题 I'd like to list the currently defined functions in dash . Is there any way of doing that? The closest I've been able to come up with is type which can be used to test if a function exist, but other than that I'm stumped. P.S. I'm talking about dash here (not bash or zsh ). 回答1: Looking at exec.c it seems that no, there is none - the table is static, there's no such functionality in the file and none of the exported functions (unsetfunc etc) appear to offer the possibility of iterating, so

How to access the prefix when using uniq -c

落花浮王杯 提交于 2019-12-25 07:47:12
问题 I encountered a problem in my program. I have a list of files and I sort them with this code to find out the 10 most frequent file types in the list. find $DIR -type f | file -b $SAVEFILES | cut -c1-40 | sort -n | uniq -c | sort -nr | head -10 My output looks like this 168 HTML document, ASCII text 114 C source, ASCII text 102 ASCII text 33 ASCII text, with very long lines 30 HTML document, UTF-8 Unicode text, with 26 HTML document, ASCII text, with very lon 21 C source, UTF-8 Unicode text 20

Bash: get all paths from path

北城余情 提交于 2019-12-24 10:53:43
问题 Say I have the path gui/site/junior/profile.py How do I get this?: gui gui/site gui/site/junior Bonus if you tell me how to loop through each path :D 回答1: You can loop with awk: awk 'BEGIN{FS=OFS="/"} { for (i=1; i<=NF; i++) { for (j=1; j<i; j++) printf "%s/", $j printf "%s\n", $i } }' <<< "gui/site/junior/profile.py" See as one liner: $ awk 'BEGIN{FS=OFS="/"}{for (i=1; i<=NF; i++) { for (j=1; j<i; j++) printf "%s%s", $j, OFS; printf "%s\n", $i}}' <<< "gui/site/junior/profile.py" gui gui/site

Redirector “<<<” in Ubuntu?

核能气质少年 提交于 2019-12-24 08:44:08
问题 I'm getting this error Syntax error: redirection unexpected in the line: if grep -q "^127.0.0." <<< "$RESULT" How I can run this in Ubuntu? 回答1: if grep -q "^127.0.0." <<< "$RESULT" then echo IF-THEN fi is a Bash-specific thing. If you are using a different bourne-compatable shell, try: if echo "$RESULT" | grep -q "^127.0.0." then echo IF-THEN fi 回答2: <<< is a bash-specific redirection operator (so it's not specific to Ubuntu). The documentation refers to it as a "Here String", a variant of

how to escape quotes in command argument to sh -c? [duplicate]

老子叫甜甜 提交于 2019-12-24 06:13:05
问题 This question already has answers here : How to escape a double quote inside double quotes? (8 answers) Closed 3 years ago . The shell command cmd may have whitespace and single and double quotes. How to escape these quotes to correctly pass the command to a POSIX shell: >dash -c ' cmd ' The other question pointed as a dup, asks about double quotes. One of the answers there is probably going to work - to split the command and use concatenated quotes. For example, if cmd were cd "dir"; ls

Run bash script with sh

心不动则不痛 提交于 2019-12-20 10:29:26
问题 I have bash script and it requires bash. Another person try to run it with sh script_name.sh And it fails because sh is symbolic link to dash in his distribution. $ ls -la /bin/sh lrwxrwxrwx 1 root root 4 Aug 25 16:06 /bin/sh -> dash I have an idea to use wrapper script: #!/bin/sh bash script_name.sh The goal is to run .sh script by sh with bash in system having symbolic link to dash. 回答1: Well, usually you use the shebang to tell the shell to use the correct interpreter: #!/bin/bash # your

Portable way to check emptyness of a shell variable [duplicate]

久未见 提交于 2019-12-18 05:44:07
问题 This question already has answers here : Why do shell script comparisons often use x$VAR = xyes? (7 answers) Closed last year . What is the portable and canonical way to test if variable is empty/undefined in a shell script? It should work in all sh-like shells. What I do now is something like: if [ -z "$var" ] ; then ... and for reverse, doing something when variable is not empty/undefined: if [ -n "$var" ] ; then ... And while these work for the scripts I write now, I'd like to know a way,

Portable way to check emptyness of a shell variable [duplicate]

删除回忆录丶 提交于 2019-12-18 05:44:02
问题 This question already has answers here : Why do shell script comparisons often use x$VAR = xyes? (7 answers) Closed last year . What is the portable and canonical way to test if variable is empty/undefined in a shell script? It should work in all sh-like shells. What I do now is something like: if [ -z "$var" ] ; then ... and for reverse, doing something when variable is not empty/undefined: if [ -n "$var" ] ; then ... And while these work for the scripts I write now, I'd like to know a way,

Linux shell script with file saving and sequential file naming

心不动则不痛 提交于 2019-12-13 03:44:33
问题 I am working with a Ethernet camera that comes with Busybox. A single board computer is connected to it through RS232. The SBC needs to send a single command to the camera in order to take a jpg snapshot, save it to a CF memory card and name it in a sequential order (0001, 0002 etc..). This is the code I use to take a single snapshot, without sequential naming: wget http://127.0.0.1/snap.php -O /mnt/0/snapfull`date +%d%m%y%H%M%S`.jpg I need the files to be named sequentially. This is the code