sh

perl inside bash: How to call perl on a script saved in a string

删除回忆录丶 提交于 2019-12-02 05:21:57
问题 I need to execute the same perl script, multiple times, on different files. To ease the process, I am trying to save the perl script as a bash string, and call perl over the string, as in the "doesn't work" part of the code below: #!/bin/sh # works perl -e 'print 1;' # doesn't work S="'print 1;'" perl -e $S perl -e $S I get the following output: 1Can't find string terminator "'" anywhere before EOF at -e line 1. Can't find string terminator "'" anywhere before EOF at -e line 1. What am I

rsync in shell for loop

牧云@^-^@ 提交于 2019-12-02 02:41:36
I have this shell script #!/bin/sh PATHS=( a b c d ) for PATH in ${PATHS[@]} do rsync -avziP /home/user/$PATH $SERVER:$server_folder -b --backup-dir=$backup_folder/backup_$date --delete --exclude=.* --log-file=$HOME/rsync.log done And I always get this error: rsync: command not found What is driving me crazy is that if I delete the for loop, and just run the rsync command, the script works perfectly PATH is a reserved variable! It is the variable specifying where to search tools (like rsync ) $ set | grep ^PATH= PATH=/home/user/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games Use

Add month to a variable date in shell script

£可爱£侵袭症+ 提交于 2019-12-02 01:55:34
问题 I have a date being passed into a shell script and have to add a month to that. for eg: passed_date=2017-06-01 i need to add 1 month to it : converted_date=2017-07-01 How can i achieve this in a shell script. I tried converting date to seconds since epoch and then adding 1 month like: date +%s -d 20170601 -d "+1 month" and then converting seconds back to yyyy-mm-dd by date -d@$(date +%s -d 20170601 -d "+1 month") +%Y-%m-%d but its basically adding 1 month to current system date 回答1: You seem

shell script in android gives [: not found

纵然是瞬间 提交于 2019-12-02 01:20:05
问题 I have this script which works on my linux machine #!/bin/sh c=1 if [ $c == 1 ] then echo c is 1 else echo c is 0 fi But when I use this in android as follows: #!/system/bin/sh c=1 if [ $c == 1 ] then echo c is 1 else echo c is 0 fi It gives an error like: [: not found EDIT Is there any other logic to check the value of $c , whether it is 1 or 0 ? Android shell have problem with [] in if so is there any other way to check the value of c ? 回答1: andriod shell sh is actually a link to busybox,

Xcode 4: custom behavior does not execute my sh script?

末鹿安然 提交于 2019-12-02 00:51:27
I created a custom behavior in Xcode 4 (Xcode > behaviors > edit behaviors > +) in order to launch a shell script (which is configured to be executable). I can invoke the behavior using the menu or my custom shortcut (console shows up as specified), but the script is not executed (no output in the console). The script has been already tested in the terminal and it works fine! and I also created a dummy script with a simple echo and the result is the same... why? How can I debug this? EDIT: After solving the problem I realized what I had in mind, if you are interested read my post: Generate

What platform independent way to find directory of shell executable in shell script?

*爱你&永不变心* 提交于 2019-12-01 22:44:51
问题 According to POSIX: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html there are some cases where it not obvious. For example: If the file is not in the current working directory, the implementation may perform a search for an executable file using the value of PATH, as described in Command Search and Execution. My Bash 4.x doesn't follow this optional rule (due to security concern??) so I can't test how it be in real life... What platform independent way to find directory of

How do i store the output of a bash command in a variable? [duplicate]

我与影子孤独终老i 提交于 2019-12-01 22:44:28
This question already has an answer here: How do I set a variable to the output of a command in Bash? 14 answers I'm trying to write a simple script for killing a process. I've already read Find and kill a process in one line using bash and regex so please don't redirect me to that. This is my code: LINE=$(ps aux | grep '$1') PROCESS=$LINE | awk '{print $2}' echo $PROCESS kill -9 $PROCESS I want to be able to run something like sh kill_proc.sh node and have it run kill -9 node But instead what I get is kill_process.sh: line 2: User: command not found I found out that when I log $PROCESS it is

Add month to a variable date in shell script

强颜欢笑 提交于 2019-12-01 22:44:01
I have a date being passed into a shell script and have to add a month to that. for eg: passed_date=2017-06-01 i need to add 1 month to it : converted_date=2017-07-01 How can i achieve this in a shell script. I tried converting date to seconds since epoch and then adding 1 month like: date +%s -d 20170601 -d "+1 month" and then converting seconds back to yyyy-mm-dd by date -d@$(date +%s -d 20170601 -d "+1 month") +%Y-%m-%d but its basically adding 1 month to current system date You seem to be looking for: date -d "20170601+1 month" +%Y-%m-%d When using multiple -d flags in the same command,

shell script in android gives [: not found

旧城冷巷雨未停 提交于 2019-12-01 21:15:38
I have this script which works on my linux machine #!/bin/sh c=1 if [ $c == 1 ] then echo c is 1 else echo c is 0 fi But when I use this in android as follows: #!/system/bin/sh c=1 if [ $c == 1 ] then echo c is 1 else echo c is 0 fi It gives an error like: [: not found EDIT Is there any other logic to check the value of $c , whether it is 1 or 0 ? Android shell have problem with [] in if so is there any other way to check the value of c ? andriod shell sh is actually a link to busybox, and it is invoked as busybox sh you need setup [ applets manually busybox ln -s /your_original_sh_path

POSIX SH build loop variable with elements containing spaces

大城市里の小女人 提交于 2019-12-01 19:46:46
Here's the code I need: #!/bin/sh x1="a1 a2" x2="b1 b2" list=SOMETHING for x in "$list" do echo $x done And the output I want: a1 a2 b1 b2 The question is: what should SOMETHING be? I want $list to behave just as $@ does. Notes: I can't use $IFS and I can't eval the entire loop. This is probably as close as you can get: #!/bin/sh x1="a1 a2" x2="b1 b2" set -- "$x1" "$x2" for x in "$@" do # echo $x echo "[${x}]" # proves that the lines are being printed separately done Output: [a1 a2] [b1 b2] In Bash you can use an array: #!/bin/bash x1="a1 a2" x2="b1 b2" list=("$x1" "$x2") for x in "${list[@]}"