sh

git with --git-dir= results in 'not a git repository'

匆匆过客 提交于 2019-12-21 03:14:07
问题 I have a script in one of my iOS apps that should get the git revision hash and put it in the version number. In this script I run git --git-dir="$PROJECT_DIR" show -s --pretty=format:%h for that. However, I get the message that the directory isn't a git repository. If I echo the PROJECT_DIR var and go to the terminal the following works: cd projectDirPath git show -s --pretty=format:%h What doesn't work is: git --git-dir=projectDirPath show -s --pretty=format:%h Am I missing something? The

How to run .sh file on Windows 7 through Cygwin?

风格不统一 提交于 2019-12-21 03:13:17
问题 I have to use a package on my Windows 7 OS but the package comes only with the .sh file so I have to use bash and hence Cygwin to run on my machine. But I am kinda familiar with Windows but completely new to Cygwin and shell programming. Suppose I have a run.sh file in /cygdrive/c/Users/myUserName/Desktop/software/myPackage/bin , how should I run it in Cygwin? Downloaded Cygwin and in the terminal I navigate to that directory and type run.sh enter but it complains $ run.sh -bash: run.sh:

POSIX sh EBNF grammar

寵の児 提交于 2019-12-20 14:21:45
问题 Is there an existing POSIX sh grammar available or do I have to figure it out from the specification directly? Note I'm not so much interested in a pure sh; an extended but conformant sh is also more than fine for my purposes. 回答1: The POSIX standard defines the grammar for the POSIX shell. The definition includes an annotated Yacc grammar. As such, it can be converted to EBNF more or less mechanically. If you want a 'real' grammar, then you have to look harder. Choose your 'real shell' and

How can I tell if a file is older than 30 minutes from /bin/sh?

浪子不回头ぞ 提交于 2019-12-20 11:00:50
问题 How do I write a script to determine if a file is older than 30 minutes in /bin/sh? Unfortunately does not the stat command exist in the system. It is an old Unix system, http://en.wikipedia.org/wiki/Interactive_Unix Perl is unfortunately not installed on the system and the customer does not want to install it, and nothing else either. 回答1: Here's one way using find . if test "`find file -mmin +30`" The find command must be quoted in case the file in question contains spaces or special

Shell loops using non-integers?

烂漫一生 提交于 2019-12-20 10:33:39
问题 I wrote a .sh file to compile and run a few programs for a homework assignment. I have a "for" loop in the script, but it won't work unless I use only integers: #!/bin/bash for (( i=10; i<=100000; i+=100)) do ./hw3_2_2 $i done The variable $i is an input for the program hw3_2_2, and I have non-integer values I'd like to use. How could I loop through running the code with a list of decimal numbers? 回答1: I find it surprising that in five years no one ever mentioned the utility created just for

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

Return a regex match in a BASH script, instead of replacing it

元气小坏坏 提交于 2019-12-20 08:57:25
问题 I just want to match some text in a BASH script, i’v tried using sed, but I can’t seem to make it just output the match instead of replacing it with something. echo -E "TestT100String" | sed 's/[0-9]+/dontReplace/g' Which will output: TestTdontReplaceString Which isn’t what I want, I want it to output: 100 Ideally I would want it to put all the matches in an array. edit: Text input is coming in as a string: newName() { #Get input from function newNameTXT="$1" if [[ $newNameTXT ]]; then #Use

How to solve “bad interpreter: No such file or directory”

随声附和 提交于 2019-12-20 08:47:09
问题 I'm trying to run a sh script and get the following error on Mac: /usr/bin/perl^M: bad interpreter: No such file or directory How can I fix this? 回答1: Remove ^M control chars with perl -i -pe 'y|\r||d' script.pl 回答2: /usr/bin/perl^M: Remove the ^M at the end of usr/bin/perl from the #! line at the beginning of the script. That is a spurious ASCII 13 character that is making the shell go crazy. Possibly you would need to inspect the file with a binary editor if you do not see the character.

Get specific line from text file using just shell script

我怕爱的太早我们不能终老 提交于 2019-12-20 07:59:11
问题 I am trying to get a specific line from a text file. So far, online I have only seen stuff like sed, (I can only use the sh -not bash or sed or anything like that). I need to do this only using a basic shell script. cat file | while read line do #do something done I know how to iterate through lines, as shown above, but what if I just need to get the contents of a particular line 回答1: sed: sed '5!d' file awk: awk 'NR==5' file 回答2: Assuming line is a variable which holds your required line

Shell line 7: [14: command not found [duplicate]

百般思念 提交于 2019-12-20 07:49:32
问题 This question already has an answer here : shell script command not found when comparing string (1 answer) Closed 3 years ago . I don't know what is the problem to fix Here is the code: #!/bin/sh while true do HOUR=$(date '+%H') TARGET=16 echo $HOUR if [$HOUR -gt $TARGET]; then mail -s "IP" "example@hotmail.com" <<EOF Global_IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//') EOF echo "Sent" fi echo "Waiting..." sleep 3600 echo "Done waiting" done Please help!