sh

sh - split string by delimiter

若如初见. 提交于 2021-01-27 23:36:36
问题 code s='id;some text here with possible ; inside' IFS=';' read -r id string <<< "$s" echo "$id" error restore.sh: 2: restore.sh: Syntax error: redirection unexpected bash version GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu) 回答1: You seem to be using sh to execute the script. Herestrings aren't supported in sh ; hence the error. Ensure that you're using bash to execute the script. 回答2: A here string is just a shortcut for a small here document. This should work in any POSIX shell:

Cross fading several audio files using sox

a 夏天 提交于 2021-01-27 21:32:04
问题 I'm trying to cross-fade several audio files together with a 3 second cross-fade and join them together in to one file with sox. I can join several files together by the command below but not sure how to cross fade between each one: sox $(ls /tmp/a*.wav | sort -n) /tmp/out/out.wav I can cross fade two files with the commands below but not sure how to combine the first line that joins several files together with the second line that splices / cross fades sox 100hz.wav 440hz.wav out.wav splice

Is there a fast way to read alternate bytes in dd

有些话、适合烂在心里 提交于 2021-01-27 18:12:21
问题 I'm trying to read out every other pair of bytes in a binary file using dd in a loop, but it is unusably slow. I have a binary file on a BusyBox embedded device containing data in rgb565 format. Each pixel is 2 bytes and I'm trying to read out every other pixel to do very basic image scaling to reduce file size. The overall size is 640x480 and I've been able to read every other "row" of pixels by looping dd with a 960 byte block size. But doing the same for every other "column" that remains

Can run a jar file without knowing the jar file name

人盡茶涼 提交于 2021-01-27 12:40:21
问题 Can any one tell how to run a jar file using java -jar command without knowing the Jar's full name, I know the prefix but the version of the jar file is dynamic,so I don't want to update my sh for every deplolyment #!/bin/bash PROJECT_HOME=/opt/services/testing-batchp PROJECT_JAR=batch-1.0.8-SNAPSHOT.jar [ -f /etc/environment ] && . /etc/environment nohup java -jar -Dspring.config.location=${PROJECT_HOME}/config/ ${PROJECT_HOME}/${PROJECT_JAR} $1 $2 >/dev/null 2>&1 & I just modified the

Can run a jar file without knowing the jar file name

老子叫甜甜 提交于 2021-01-27 12:39:49
问题 Can any one tell how to run a jar file using java -jar command without knowing the Jar's full name, I know the prefix but the version of the jar file is dynamic,so I don't want to update my sh for every deplolyment #!/bin/bash PROJECT_HOME=/opt/services/testing-batchp PROJECT_JAR=batch-1.0.8-SNAPSHOT.jar [ -f /etc/environment ] && . /etc/environment nohup java -jar -Dspring.config.location=${PROJECT_HOME}/config/ ${PROJECT_HOME}/${PROJECT_JAR} $1 $2 >/dev/null 2>&1 & I just modified the

How can I do bash arithmetic with variables that are numbers with leading zeroes? [duplicate]

杀马特。学长 韩版系。学妹 提交于 2021-01-27 07:02:55
问题 This question already has answers here : How can I increment a number in a while-loop while preserving leading zeroes (BASH < V4) (3 answers) incrementing a number in bash with leading 0 (8 answers) Closed 2 years ago . I have the following code in a bash script, where "values" is a variable of newline separated numbers, some of which have leading 0's , and I am trying to iterate through each value in values and add each value to the variable "sum". sum=0 while read line; do sum=$(( sum +

How can I do bash arithmetic with variables that are numbers with leading zeroes? [duplicate]

对着背影说爱祢 提交于 2021-01-27 07:01:21
问题 This question already has answers here : How can I increment a number in a while-loop while preserving leading zeroes (BASH < V4) (3 answers) incrementing a number in bash with leading 0 (8 answers) Closed 2 years ago . I have the following code in a bash script, where "values" is a variable of newline separated numbers, some of which have leading 0's , and I am trying to iterate through each value in values and add each value to the variable "sum". sum=0 while read line; do sum=$(( sum +

How to fire a command when a shell script is interrupted?

二次信任 提交于 2021-01-27 04:06:32
问题 I want to fire a command like " rm -rf /etc/XXX.pid " when the shell script is interrupted in the middle of its execution. Like using CTRL+C Can anyone help me what to do here? 回答1: Although it may come as a shock to many, you can use the bash built-in trap to trap signals :-) Well, at least those that can be trapped, but CTRL-C is usually tied to the INT signal. You can trap the signals and execute arbitrary code. The following script will ask you to enter some text then echo it back to you.

Concatenate inputs in string while in loop

老子叫甜甜 提交于 2021-01-27 02:55:00
问题 I have a variable of sources that is basically a string of comma-separated elements: SOURCES="a b c d e" I want the user to input one destination for each of this source, and I want hence to store this input into a string looking like the above but containing the destinations. If I want to assign a=1, b=2... etc, I would have something like this: echo $DESTINATIONS >>> "1 2 3 4 5" In order to do the above, I do this: SOURCES="a b c d e" DESTINATIONS="" for src in $SOURCES do echo Input

Concatenate inputs in string while in loop

安稳与你 提交于 2021-01-27 02:54:11
问题 I have a variable of sources that is basically a string of comma-separated elements: SOURCES="a b c d e" I want the user to input one destination for each of this source, and I want hence to store this input into a string looking like the above but containing the destinations. If I want to assign a=1, b=2... etc, I would have something like this: echo $DESTINATIONS >>> "1 2 3 4 5" In order to do the above, I do this: SOURCES="a b c d e" DESTINATIONS="" for src in $SOURCES do echo Input