sh

Randomly shuffling lines in Linux / Bash

送分小仙女□ 提交于 2020-01-18 21:34:27
问题 I have some files in linux. For example 2 and i need shuffling the files in one file. For example $cat file1 line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 and $cat file2 linea one linea two linea three linea four linea five linea six linea seven linea eight And later that i shuffling the two files i can obtain something like: linea eight line 4 linea five line 1 linea three line 8 linea seven line 5 linea two linea one line 2 linea four line 7 linea six line 1 line 6 回答1: You should

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

how to append a value to a variable in shell script

独自空忆成欢 提交于 2020-01-16 04:45:09
问题 I am getting a variable value from properties and I am able to access in sh file. but I am unable to append another value to that variable. Kindly suggest. $ echo "Build ID from properties:"$BUILD_ID Build ID from properties: abcd_v6_c1 $ echo " num----------------" build_${BUILD_ID}.zip .zip---------------- build_abcd_v6_c1 Kindly suggest how to append .zip value. 回答1: It seems you have a Windows carriage return in your $BUILD_ID variable. To check, try this command (the carriage return will

Read list of files and copy deleted files back

こ雲淡風輕ζ 提交于 2020-01-16 01:15:07
问题 I did a mercurial merge which deleted a few files which i need in the new branch so i generated a list of the deleted files and am now trying to build a shell script to copy the deleted files back but so far it is not working.The script is question is cat deltedfiles | xargs -I {} bash -c 'cut -d" " -f1 "{}"|grep -Fq "R" && echo {}' Can somebody tell me how do i correct this? I just get an error from cut saying that the file does not exist and the whole line which i understand to be is cut is

echo the set of variables while going through a loop

六月ゝ 毕业季﹏ 提交于 2020-01-15 11:59:24
问题 Can someone help me. I've been trying alternatives but I still get the same output. Here is my script #!/bin/sh field1="a" field2="s" field3="d" field4="f" field5="g" for i in {1..5} do var1="field"$i echo $var1 var2="$"$var1 echo $var2 echo $field1 done Here is my output field1 $field1 a field2 $field2 a field3 $field3 a field4 $field4 a field5 $field5 a what I'm trying to do is get an output like a s d f g 回答1: You're looking for ${!var1} — a Bash-specific shell parameter expansion. field1=

Using variables inside a bash heredoc

不羁岁月 提交于 2020-01-15 11:22:08
问题 I'm trying to interpolate variables inside of a bash heredoc: var=$1 sudo tee "/path/to/outfile" > /dev/null << "EOF" Some text that contains my $var EOF This isn't working as I'd expect ( $var is treated literally, not expanded). I need to use sudo tee because creating the file requires sudo. Doing something like: sudo cat > /path/to/outfile <<EOT my text... EOT Doesn't work, because >outfile opens the file in the current shell, which is not using sudo. 回答1: In answer to your first question,

Execute script over SSH and get output? [duplicate]

 ̄綄美尐妖づ 提交于 2020-01-15 07:42:06
问题 This question already has answers here : Running a Bash script over ssh (5 answers) Closed 3 years ago . I am trying to execute a command in a remote machine and get the output. I have tried implementing below shell script but unable to get the content. #!/bin/bash out=$(ssh huser@$source << EOF while IFS= read -r line do echo 'Data : ' $line done < "data.txt" EOF ) echo $out Output: Data : Data : Data : I could see the "Data :" is printed 3 times because the file "data.txt" has 3 lines of

Inserting Variable into sh Script Command [duplicate]

╄→尐↘猪︶ㄣ 提交于 2020-01-14 09:33:19
问题 This question already has answers here : Filename not printing correctly with underscore “_” in Bash [duplicate] (2 answers) Error in string Concatenation in Shell Scripting (3 answers) bash variable interpolation separate variables by a hyphen or underscore (3 answers) When do we need curly braces around shell variables? (7 answers) Closed 2 years ago . #!/bin/sh -f set proj_dir="OutputDir" for projname in lib proj1 proj2 do mv ./scripts/$projname_BYTECODE ./$proj_dir/scripts/$projname done

Capturing the output of “diff” with org-babel

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-13 08:22:28
问题 I'm trying to capture the output of diff with org-babel, but for some reason it's not working. For the files 1 a b c 2 a c b diff 1 2 called from the command line returns 1c1 < a b c --- > a c b But with org-babel, nothing: #+begin_src sh diff 1 2 #+end_src #+RESULTS: The minibuffer reads "Code block produced no output". The org-babel error output window is empty. Other commands such as ls show the output as expected. I'm not familiar with org-babel. I tried using :results output verbatim ,

Using jq to parse JSON in launchd

房东的猫 提交于 2020-01-11 12:06:17
问题 I have a shell script that evaluates a folder full of JSON files which runs fine when invoked directly but fails when run from launchd. Specifically, launchd fails on this line: current_file_snapshots=$(cat $current_file | jq '.snapshots | length') Because: jq: command not found I looked through the jq docs to figure this out, but there's no mention of this problem. I haven't been able to figure out how to get jq (or any similar third party tool) to work through launchd. Thanks! 回答1: Ahh,