sh

Check number of running scripts using ps

一个人想着一个人 提交于 2019-12-19 10:20:30
问题 I'm writing a script (show_volume.sh) which may be called several times in short intervals. I need a way to determine whether there is more than just one running instance of this script. I figured I could use ps , so I wrote this function in Bash: is_only_process(){ PCOUNT=`ps -a | grep show_volume.sh | wc -l` echo $PCOUNT if (( PCOUNT==1 )); then return 1 fi return 0 } So I added these 2 lines is_only_process sleep 4 and started this script once, but the output of echo $PCOUNT does not make

Facebook iOS SDK - How to build static library for Xcode 4.3?

拥有回忆 提交于 2019-12-19 03:15:41
问题 I'm integrating Facebook to my iOS ARC app by following instructions in this link. i'm stuck at building static library step. https://developers.facebook.com/docs/mobile/ios/build/ I'm using Xcode 4.3 (Developer folder now moved inside the Application) so the script "build_facebook_ios_sdk_static_lib.sh" didn't work. I've tried to modified the script but wasn't successful. Could someone please help? Thanks ! 回答1: just edit "build_facebook_ios_sdk_static_lib.sh" with TextEdit and change:

How to tell if any command in bash script failed (non-zero exit status)

回眸只為那壹抹淺笑 提交于 2019-12-18 14:49:33
问题 I want to know whether any commands in a bash script exited with a non-zero status. I want something similar to set -e functionality, except that I don't want it to exit when a command exits with a non-zero status. I want it to run the whole script, and then I want to know that either: a) all commands exited with exit status 0 -or- b) one or more commands exited with a non-zero status e.g., given the following: #!/bin/bash command1 # exits with status 1 command2 # exits with status 0 command3

How to perform bitwise operations on hexadecimal numbers in bash?

你离开我真会死。 提交于 2019-12-18 14:16:07
问题 In my bash script I have a string containing a hexadecimal number, e.g. hex="0x12345678" . Is it possible to treat it as a hex number and do bit shifting on it? 回答1: You can easily bitshift such numbers in an arithmetic context: $ hex="0x12345678" $ result=$((hex << 1)) $ printf "Result in hex notation: 0x%x\n" "$result" 0x2468acf0 回答2: Of course you can do bitwise operations (inside an Arithmetic Expansion): $ echo "$((0x12345678 << 1))" 610839792 Or: $ echo "$(( 16#12345678 << 1 ))"

envsubst: command not found on Mac OS X 10.8

泪湿孤枕 提交于 2019-12-18 10:22:49
问题 When I try to run a script that contains the envsubst command, I get this error. Looking online, this seems to be a standard bash command, so I am not sure what to install in order to get it to work. 回答1: Edit: @cobberboy 's anwer is more correct. upvote him. brew install gettext brew link --force gettext Following is my old answer: envsubst is included in gettext package. Therefore you may compile it by your own, using standard build tools such as make or using homebrew . However, it seems

Running Executable from Shell Script

我怕爱的太早我们不能终老 提交于 2019-12-18 08:49:26
问题 I am having trouble launching an executable that I have created from a shell script. I would like to automate testing by running the program many times with different command line options to verify it is working. When I type echo $SHELL , /bin/sh is displayed. The following is my shell script: #!/bin/sh clear echo "Running first test." ./myProgram exit 0 When I run the script ( sh myScript.sh ), with myProgram in the same directory, I see the following output: Running first test. : not

UNIX date: How to convert week number to a date range (Mon-Sun)?

和自甴很熟 提交于 2019-12-18 05:57:45
问题 I have list of week numbers extracted from huge log file, they were extracted using syntax: $ date --date="Wed Mar 20 10:19:56 2012" +%W; 12 I want to create a simple bash function which can convert these week numbers to a date range. I suppose function should accept 2 arguments: $number and $year, example: $ week() { ......... } $ number=12; year=2012 $ week $number $year "Mon Mar 19 2012" - "Sun Mar 25 2012" 回答1: With GNU date : $ cat weekof.sh function weekof() { local week=$1 year=$2

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,

sh read command eats slashes in input?

℡╲_俬逩灬. 提交于 2019-12-18 05:28:07
问题 Perhaps easiest to explain with an example: $ echo '\&|' \&| $ echo '\&|' | while read in; do echo "$in"; done &| It seems that the "read" command is interpreting the slashes in the input as escapes and is removing them. I need to process a file line by line without changing its contents and I'm not sure how to stop read from being smart here. Any ideas? 回答1: Accrding to: http://www.vias.org/linux-knowhow/bbg_sect_08_02_01.html : -r If this option is given, backslash does not act as an escape