shell

Editing plist file using shell script

孤街浪徒 提交于 2021-02-05 20:00:29
问题 I have used pkgbuild to create a default Component Property List file. The file looks like: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList- 1.0.dtd"> <plist version="1.0"> <array> <dict> <key>BundleHasStrictIdentifier</key> <true/> <key>BundleIsRelocatable</key> <true/> <key>BundleIsVersionChecked</key> <true/> <key>BundleOverwriteAction</key> <string>upgrade</string> <key>RootRelativeBundlePath</key> <string

How to bypass an ampersand (&) without using quotes when receiving an URL as an argument to a shell script?

余生颓废 提交于 2021-02-05 12:31:06
问题 I'm building a shell script (trying to be POSIX compliant) and I'm stuck in an issue. The script is supposed to receive an URL and do some things with it's content. myscript www.pudim.com.br/?&args=ok The thing is, the ampersand symbol is interpreted as a command additive, and giving to my script only the www.pudim.com.br/? part as an argument. I know that the right workaround would be to surround the URL with quotes but, because I need to use this script several times in a row, I wanted to

Escape single quotes in shell script

寵の児 提交于 2021-02-05 11:28:40
问题 I need to escape single quotes in a variable. ssh_command 'file=$(hostname)_server-setup_$(date +%Y-%m-%d).tar.gz && cd /var && tar -zcvf $file ini | wc -l | xargs printf \'Num files: %d, File: $file\'' I can surround the variable with double quotes but then the internal variables will be evaluated when the variable is declared, and that's not what I want. ssh_command "file=$(hostname)_server-setup_$(date +%Y-%m-%d).tar.gz && cd /var && tar -zcvf $file ini | wc -l | xargs printf 'Num files:

why subtraction return - symbol

懵懂的女人 提交于 2021-02-05 11:18:04
问题 I have a problem with a simple subtraction but I don't understand what's wrong. My code : start= date +%s%N | cut -b1-13 #Treatment... end= date +%s%N | cut -b1-13 delta=`expr $end - $start` echo "delta $delta" My console display : 1374652348283 ... 1374652349207 delta - My question is : Why do I got a - symbol returned ? 回答1: The command: a= b (note the space) will set a to an empty string while it runs the command b . It's a way to temporarily set environment variables for a single command,

Change file's numbers Bash

眉间皱痕 提交于 2021-02-05 09:46:02
问题 I need to implement a script (duplq.sh) that would rename all the text files existing in the current directory using the command line arguments. So if the command duplq.sh pic 0 3 was executed, it would do the following transformation: pic0.txt will have to be renamed pic3.txt pic1.txt to pic4.txt pic2.txt to pic5.txt pic3.txt to pic6.txt etc… So the first argument is always the name of a file the second and the third always a positive digit. I also need to make sure that when I execute my

Change file's numbers Bash

情到浓时终转凉″ 提交于 2021-02-05 09:44:08
问题 I need to implement a script (duplq.sh) that would rename all the text files existing in the current directory using the command line arguments. So if the command duplq.sh pic 0 3 was executed, it would do the following transformation: pic0.txt will have to be renamed pic3.txt pic1.txt to pic4.txt pic2.txt to pic5.txt pic3.txt to pic6.txt etc… So the first argument is always the name of a file the second and the third always a positive digit. I also need to make sure that when I execute my

perl bash script don't insert sql query

有些话、适合烂在心里 提交于 2021-02-05 09:30:34
问题 i want to insert a query but not work : my $query1 = $db1->prepare("SELECT host, name, severity FROM XX"); my $query2 = $db2->prepare('UPDATE worldmap_table' . ' SET severity = ?, name = ? WHERE HOST = ?'); $query1->execute; while (my @row = $query1->fetchrow_array) { $query2->execute($row[2]); print "$row[2]\n"; } preparation query 3 my $query3 = $db1->prepare("SELECT host, name, severity FROM XX); preparation query 4 my $query4 = $db2->prepare('UPDATE worldmap_table' . ' SET severity = 6,

What does this shell test achieve

独自空忆成欢 提交于 2021-02-05 09:25:32
问题 I have a very simple question that I can't answer. In shell, what would this command do: test -d $VIRTUAL_ENV || virtualenv $VIRTUAL_ENV It seems like it tests if the virtualenv directory exists, but I dont understand what if does with that information. Will it always create the virtualenv afterwards, or would it only do it if it doesn't already exist? 回答1: The || is the OR condition. Hence, this will test if $VIRTUAL_ENV directory exists. If not, it will run virtualenv $VIRTUAL_ENV . Other

Unable to read from user in rpm install script

£可爱£侵袭症+ 提交于 2021-02-05 09:24:08
问题 I've Created RPM Package which contains shell script code which shown below. When I'm installing it in RedHat OS, It is not taking user input and continuously looping. If I run the same file manually it's working fine. If Anybody Knows Please let me know. set +e IpAddress='0' condition=1 while [[ $condition -ne 0 ]] do echo ' ' echo "PLEASE PROVIDE APPLIANCE IP" read IpAddress if valid_ip $IpAddress; then condition=0 else echo $IpAddress " IS INVALID IP PLEASE PROVIDE A VALID IP: " echo ' '

How to disable stdout buffer when running shell

假如想象 提交于 2021-02-05 08:54:07
问题 I am using Python to call a Shell script with def run_command(cmd): print "Start to run: " + cmd run = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while True: line = run.stdout.readline().decode()[:-1] if line == '' and run.poll() is not None: break print line # print the log from shell recode = run.returncode if recode != 0: raise Exception("Error occurs!") print "End to run: " + cmd Then I run run_command("sh /home/tome/a.sh") I notice the console