sh

Cocoa run AppleScript that already contains double quotes

烈酒焚心 提交于 2019-12-01 09:57:35
问题 I have a Cocoa application that need admin permission to execute a cmd, but in some extreme case like filename containing double quote, this code does not work. NSString *fileName = @"~/Documents/My\" File/"; NSString *cmd = [NSString stringWithFormat:@"chown -R '%@' '%@';NSUserName(), fileName]; NSString *cmd_execute = [NSString stringWithFormat:@"do shell script \"%@\" with administrator privileges",cmd_execute]; //This line is the problem, our %@ contains double quote, so cocoa //cannot

get parent directory of a file in bash

眉间皱痕 提交于 2019-12-01 08:48:34
问题 How do I get a parent directory for a file? I want it to be safe on all kind of names: . .. path/to/my/file /absolute/path/to/my/file '-rf --no-preserve-root whatever'/test.zip (symbolic links) `'"`'{(}) I am more interested getting the canonical location on the file system than in traversing the path stated in the filename. Note that there are similar questions to this one, but none of them focuses on correctness, relative/absolute paths and "unsafe" names: [1] bash get the parent directory

script doesn't run while executing in clearcase

一个人想着一个人 提交于 2019-12-01 08:45:13
问题 I am trying to execute the following build script and it is returning no error but it is not executing the script inside it. there is a view tag with the following name. it can be seen with cleartool lsview <view-tag> . I can do cleartool setview <view-tag> but it doesn't run the sh /abc/cds/fg/bin/ant -t all. CLEARCASE_VIEWNAME=NYC_CYN cleartool setview -exec "newgrp orange; cd /abc/cds/fg/bin; sh /abc/cds/fg/bin/ant -t all -i ' '" $CLEARCASE_VIEWNAME Thanks for any help !! 回答1: First, don't

QProcess and shell : Destroyed while process is still running

…衆ロ難τιáo~ 提交于 2019-12-01 08:20:55
I want to launch a shell script with Qt. QProcess process; process.start(commandLine, QStringList() << confFile); process.waitForFinished(); if(process.exitCode()!=0) { qDebug () << " Error " << process.exitCode() << process.readAllStrandardError(); } else { qDebug () << " Ok " << process.readAllStrandardOutput() << process.readAllStrandardError(); } The result is : Ok : Result.... " "" QProcess : Destroyed while process is still running. This message does not appear every time. What is the problem? process.waitForFinished(); is hitting the default 30 seconds timeout. Use process

printf field width doesn't support multibyte characters?

和自甴很熟 提交于 2019-12-01 08:02:58
问题 I want printf to recognize multi-byte characters when calculating the field width so that columns line up properly... I can't find an answer to this problem and was wondering if anyone here had any suggestions, or maybe a function/script that takes care of this problem. Here's a quick and dirty example: printf "## %5s %5s %5s ##\n## %5s %5s %5s ##\n" '' '*' '' '' "•" '' >## * ## >## • ## Obviously, I want the result: >## * ## >## • ## Any way to achieve this? 回答1: The best I can think of is:

How to subtract a year from a date stored in a variable in shell script?

巧了我就是萌 提交于 2019-12-01 07:51:49
问题 as_of_dt='2016-01-01' as_of_dt_prev_year=$($as_of_dt -d '-1 year' +'%Y-%m-%d') echo $as_of_dt_prev_year This does not work. error: -d: command not found However this works if we use '$date' instead of $as_of_dt. 回答1: Played around with it. This seems to work: as_of_dt='2016-01-01' as_of_dt_prev_year=$(date --date="${as_of_dt} -1 year" +'%Y-%m-%d') echo $as_of_dt_prev_year Note the double quotes that are needed for variable substitution to work. 来源: https://stackoverflow.com/questions/51259249

Find maximum positive integer value in Bourne Shell

我只是一个虾纸丫 提交于 2019-12-01 06:57:27
问题 I'm checking a counter in a loop to determine if it's larger than some maximum, if specified in an optional parameter. Since it's optional, I can either default the maximum to a special value or to the maximum possible integer. The first option would require an extra check at each iteration, so I'd like to instead find out what is the maximum integer that will work with the -gt Bourne Shell operation . 回答1: I'd stay clear of integer limits as they're non portable and problematic $ test

Possible to urlencode a variable in a shell script?

独自空忆成欢 提交于 2019-12-01 06:49:17
Is it possible to url encode a variable within a shell script? #!/bin/bash now=$(date +"%T") DATA=$(wget -q -O - "http://someurl.com/x.htm?callback=webRequest&exthrs=1&extMode=&fund=1&entitlement=0&skipcache=&extendedMask=1&partnerId=2&output=json&noform=1") wget -q -O - "http://somewhere.com?abc=$1&responseData=$DATA" echo "-----COMPLETE----- $now $1 $RANDOM " I want to url encode the DATA variable, since its results have & in it, it messes up the params in the second wget, is there a way to url encode that DATA variable without using PHP to url encode? Here is one method for URL encoding the

Possible to urlencode a variable in a shell script?

浪子不回头ぞ 提交于 2019-12-01 05:46:14
问题 Is it possible to url encode a variable within a shell script? #!/bin/bash now=$(date +"%T") DATA=$(wget -q -O - "http://someurl.com/x.htm?callback=webRequest&exthrs=1&extMode=&fund=1&entitlement=0&skipcache=&extendedMask=1&partnerId=2&output=json&noform=1") wget -q -O - "http://somewhere.com?abc=$1&responseData=$DATA" echo "-----COMPLETE----- $now $1 $RANDOM " I want to url encode the DATA variable, since its results have & in it, it messes up the params in the second wget, is there a way to

sourcing env output

蓝咒 提交于 2019-12-01 05:32:10
I have some shell code I need to be debug, so I had the code dump its environment into a file env > env.txt and with my testing script I want to source it, test.sh: . ./env.txt echo $EXAMPLE echo $EXAMPLE2 the contents of env.txt are: EXAMPLE=sh /hello/command.sh EXAMPLE2=/just/some/path but, env does not put quotes around its values, which tends to cause a issue for $EXAMPLE, I get this error test.sh: /hello/command.sh: not found so clearly it is trying to run it instead of setting the variables. what do you find is the quickest workaround for this problem? while read line; do declare "$line"