sh

What do I need to quote in sed command lines?

旧巷老猫 提交于 2019-12-07 12:54:01
问题 There are many questions on this site on how to escape various elements for sed, but I'm looking for a more general answer. I understand that I might want to escape some characters to avoid shell expansion: Bash: Single quoted [strings] ('') are used to preserve the literal value of each character enclosed within the quotes. [However,] a single quote may not occur between single quotes, even when preceded by a backslash. The backslash retains its meaning [in double quoted strings ] only when

Difference between pgrep in sh and bash

非 Y 不嫁゛ 提交于 2019-12-07 08:47:38
问题 Here is a test: $ bash -c "pgrep -f novalidname" $ sh -c "pgrep -f novalidname" 11202 Why is pgrep giving output when run from sh ? (As far as I can see, there are no processes on my computer that is named novalidname ) 回答1: It's probably a timing issue and pgrep finds itself, as you're issuing it with -f and novalidname is present in the command line. Try with -l to confirm. 回答2: The actual explanation: Regardless of flags, pgrep never returns its own PID. If you execute bash -c with a

Bash convert string to timestamp

旧城冷巷雨未停 提交于 2019-12-07 05:10:29
I have a string in format 20141225093000 which represents Dec 25, 2014 09:30:00 and I want to convert the original format to a unix timestamp format so i can do time operations on it.How would I do this in bash? I can easily parse out the values with expr but I was hoping to be able to identify a format like YYYYmmddHHMMSS and then convert it based on that. With GNU date, you can convert YYYY-MM-DDTHH:MM:SS to epoch time (seconds since 1-1-1970) easily, like so: date -d '2014-12-25T09:30:00' +%s To do this starting without any delimiters: in=20141225093000 rfc_form="${in:0:4}-${in:4:2}-${in:6

How to format The mail Output of Bash Shell Script

落爺英雄遲暮 提交于 2019-12-07 02:55:45
I have a Bash shell script which send an email in every day at certain time. the code is as follows: first_dir=/test1 second_dir=/test2 email=me@me.com allfiles=$(find /test1 /test2 -maxdepth 1 | sort) IFS=$'\n' while true do sleep 24h [ "$allfiles" != "" ] && find $allfiles -maxdepth 1 -printf '%Tc\t%s\t%p\n' | mail -s "List Of All Files" "$email" files="$allfiles" done This script is giving output in Single column. but I want the Output in two columns. 1st column with files of first_dir=/test1 2nd column with files of second_dir=/test2 If you want them separated like that, don't join them

Bourne shell version [closed]

我的梦境 提交于 2019-12-07 00:10:31
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago . How to determine version of Bourne shell ( /bin/sh) on Solaris 10 machine? 回答1: I don't believe there's any way to do that directly. Why do you need to know? 回答2: Never worked on solaris, but how about sh --version ? Workes on ubuntu & mac. 来源: https://stackoverflow.com/questions/5143469/bourne-shell-version

How to watch file changes on Mac OSX using FSWatch?

末鹿安然 提交于 2019-12-06 23:52:37
问题 I'm trying to use fswatch to translate the following lines from a linux bash script to be able to run it on Mac OSX: inotifywait -r -m 'myfolder/' | while read MODFILE do echo "something" done Since inotifywait doesn't work on Mac OSX I want to substitute the first line for FSWatch. Although the README refers to the fswatch man page, it doesn't provide a link to it and a search around the internet doesn't get me anything. So I tried messing around a bit. I created a folder called testfswatch/

Default Docker entrypoint

早过忘川 提交于 2019-12-06 17:18:07
问题 I am creating an image from another image that set a specific entrypoint. However I want my image to have default one. How do I reset the ENTRYPOINT? I tried the following Dockerfile: FROM some-image ENTRYPOINT ["/bin/sh", "-c"] Unfortunately it doesn't work like the default entrypoint as it need the command to be quoted. docker run myimage ls -l / # "-l /" arguments are ignored file1 file2 file3 # files in current working directory docker run myimage "ls -l /" # works correctly How do I use

How to pass an asterisk to module “sh” in python?

心不动则不痛 提交于 2019-12-06 16:47:49
I'm using the "sh" module in python in order to call external commands on Linux. In my particular case I would like to call the "du" command because it is more efficient than doing such calculations "by hand". Unfortunately the following line does not work: output = sh.du('-sx', '/tmp/*') But this does work: output = sh.du('-sx', '/tmp/') If I pass an asterisk I get the following error message: 'ascii' codec can't encode character u'\u2018' in position 87: ordinal not in range(128) Does anyone know how to deal with asterisks in command line arguments? As requested, here is the stack trace:

Which `[` can not compare empty strings?

天大地大妈咪最大 提交于 2019-12-06 15:39:46
In some ancient Shell scripts for Solaris I found the following notation to check if a variable is empty: [ x"$var" = x ] On a current Linux system I would write it just as [ "$var" = "" ] or [ -z "$var" ] Which version of [ actually requires the first notation? None.The alias from [] to test appears after the option -z of test. Therefore, if you can use [ x"$var" = x] , you can also write [ -z "$var" ] . 来源: https://stackoverflow.com/questions/35365744/which-can-not-compare-empty-strings

Bash script fails when running command with embedded quotes (source parameters)

孤街醉人 提交于 2019-12-06 15:03:08
问题 I'm using source to insert generated variables into a string from a file in order to execute that string from a bash script. I've echoed the generated string to compare to one that works from the command line and I can't seem to see any difference, but the bash command fails as it seems the supplied parameters are getting mixed up somewhere in the middle. I've escaped double quotes around the ice_name string, so it looks identical to the one that works when I echo it Do I need to escape other