sh

Git post-commit hook as a background task

不问归期 提交于 2019-11-28 06:58:41
问题 I have a script, that I need to run after committing to a project under git revision control. Therefore I created a post-commit hook in my projects .git directory in the subdirectory /hooks, named it 'post-commit' and gave it the following contents: #!/bin/sh # I am a post-commit hook /usr/local/bin/my_script & my_script is executable and runs fine in /bin/sh. In fact it has a runtime of several seconds, so I want it to be backgrounded and detached from the current shell. That's why I put the

difference between sh and bash when symlink is used

别说谁变了你拦得住时间么 提交于 2019-11-28 05:50:32
问题 I have a shell script which uses process substitution The script is: #!/bin/bash while read line do echo "$line" done < <( grep "^abcd$" file.txt ) When I run the script using sh file.sh I get the following output $sh file.sh file.sh: line 5: syntax error near unexpected token `<' file.sh: line 5: `done < <( grep "^abcd$" file.txt )' When I run the script using bash file.sh , the script works. Interestingly, sh is a soft-link mapped to /bin/bash . $ which bash /bin/bash $ which sh /usr/bin/sh

Replacement for source in sh

浪子不回头ぞ 提交于 2019-11-28 05:11:53
I need to set the environment variables, usually we do this by source script.sh But now, I am automating it during the boot process and it looks like the root boots by default with sh shell. How do I source this script in sh ? The dot command ' . ' is the equivalent of the C Shell (and Bash) source command. It is specified by POSIX (see dot ), and supported by the Bourne and Korn shells (and zsh , I believe). . somefile Note that the shell looks for the file using $PATH , but the file only has to be readable, not executable. As noted in the comments below, you can of course specify a relative

Assigning the output of a command to a variable

可紊 提交于 2019-11-28 04:37:42
I am new with unix and I am writing a shell script. When I run this line on the command prompt, it prints the total count of the number of processes which matches: ps -ef | awk '/siebsvc –s siebsrvr/ && !/awk/ { a++ } END { print a }' example, the output of the above line is 2 in the command prompt. I want to write a shell script in which the output of the above line (2) is assigned to a variable, which will be later be used for comparison in an if statement. I am looking for something like output= `ps -ef | awk '/siebsvc –s siebsrvr/ && !/awk/ { a++ } END { print a }'` echo $output But when i

How to start process via SSH, so it keeps running?

我是研究僧i 提交于 2019-11-28 03:42:53
问题 I have three files: monitor.sh, which starts python scripts: sudo python ./webCheck & sudo python ./apiCheck & and the otherones, webCheck & apiCheck: it is supposed to run in the background, after I close the terminal. It checks my other website's availability, in an endless loop. I can't get it to work, I am trying nohup, but can't get the syntax right. webCheck have to be run with sudo. Does nohup be included also in the sh script? I guess as the monitor.sh is just supposed to start other

Running a script after startx automatically [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 03:37:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . With my Raspberry Pi, I managed to login pi user automatically, then start tomcat automatically and then start X server as well. For those interested, auto login: 1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1 instead of 1:2345:respawn:/sbin/getty 115200 tty1 in /etc/inittab and sh /home/pi

strip comments from xml file and pretty-print it

我是研究僧i 提交于 2019-11-28 02:46:06
问题 I have this huge xml file which contains a lot of comments. Whats the "best way" to strip out all the comments and nicely format the xml from the linux command line? 回答1: you can use tidy $ tidy -quiet -asxml -xml -indent -wrap 1024 --hide-comments 1 tomcat-users.xml <?xml version='1.0' encoding='utf-8'?> <tomcat-users> <user username="qwerty" password="ytrewq" roles="manager-gui" /> </tomcat-users> 回答2: Run your XML through an identity transform XSLT, with an empty template for comments. All

Bourne Shell Left Right Justify

南楼画角 提交于 2019-11-28 02:06:06
问题 I am trying to do some formatting on output data in a script and not positive how to do Left Right justify as well as width. Can anyone point me in the right direction? 回答1: you can use printf. examples $ printf "%15s" "col1" $ printf "%-15s%-15s" "col1" "col2" tools like awk also has formatting capabilities $ echo "col1 col2" | awk '{printf "%15s%15s\n", $1,$2}' col1 col2 回答2: You're not being very clear, but the easiest way is probably to just use printf() (the shell command, not the C

Alias doesn't work inside a Bash script

橙三吉。 提交于 2019-11-28 02:05:28
I have an executable file command.sh #/bin/bash alias my_command='echo ok' my_command My terminal is bash. When I run it like ./command.sh , it works fine. When I run it like /bin/bash ./command.sh , it can't find a my_command executable. When I run it like /bin/sh ./command.sh , it works fine. I'm confused here. Where's the problem? From the bash man page: Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below). In other words, aliases are not enabled in bash shell

/bin/sh: Odd string comparison error 'unexpected operator' [duplicate]

折月煮酒 提交于 2019-11-28 01:44:37
This question already has an answer here: Unexpected operator error [duplicate] 4 answers Found this error to be quite weird because previously my script was working and but after I moved it from the server I was working on to my local machine, it stopped working and just gave me an 'unexpected operator' error. # Else if the script is being run in the arrayscripts directory, add /output/ ... elif [ $basePath == "arrayscripts" ]; then echo "$dscr has started to run." cpuPath="`pwd`/output/cpu.binary" txtPath="`pwd`/output/cpu.txt" csvPath="`pwd`/output/cpu.csv" If your actual shell is /bin/sh