sh

Using jq to parse JSON in launchd

荒凉一梦 提交于 2020-01-11 12:06:09
问题 I have a shell script that evaluates a folder full of JSON files which runs fine when invoked directly but fails when run from launchd. Specifically, launchd fails on this line: current_file_snapshots=$(cat $current_file | jq '.snapshots | length') Because: jq: command not found I looked through the jq docs to figure this out, but there's no mention of this problem. I haven't been able to figure out how to get jq (or any similar third party tool) to work through launchd. Thanks! 回答1: Ahh,

Pass parameters that contain whitespaces via shell variable

早过忘川 提交于 2020-01-11 11:29:09
问题 I've got a program that I want to call by passing parameters from a shell variable. Throughout this question, I am going to assume that it is given by #!/bin/sh echo $# i.e. that it prints out the number of arguments that are passed to it. Let's call it count-args . I call my program like this: X="arg1 arg2" count-args $X This works quite well. But now one of my arguments has a whitespace in it and I can't find a way to escape it, e.g. the following things do not work: X="Hello\ World" X=

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

拟墨画扇 提交于 2020-01-11 10:25:30
问题 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:

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

走远了吗. 提交于 2020-01-11 10:24:29
问题 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:

bash: Delete all files older than 1 month, but leave files from Mondays

本小妞迷上赌 提交于 2020-01-10 18:45:12
问题 I have a lot of daily backup archives. To manage disk usage, I need a bash script that will delete all files older than 1 month, but keep all files created on Mondays, even if they are older than 1 month. For example, this will delete all files last modified more than 30 days ago: find /path/to/files* -type f -mtime +30 -delete But I don't really know how to keep files created on Mondays. 回答1: Slightly simpler and more cautious version of @JoSo's answer: find /path/to/files -type f -mtime +30

How to echo multi lined strings in a Bourne shell [duplicate]

蓝咒 提交于 2020-01-09 10:38:43
问题 This question already has answers here : When to wrap quotes around a shell variable? (5 answers) Closed 4 years ago . I want to create some scripts for filling some templates and inserting them into my project folder. I want to use a shell script for this, and the templates are very small so I want to embed them in the shell script. The problem is that echo seems to ignore the line breaks in my string. Either that, or the string doesn't contain line breaks to begin with. Here is an example:

Escaping a dollar sign in Unix inside the cat command

有些话、适合烂在心里 提交于 2020-01-09 09:47:27
问题 On Ubuntu, I would like to end up with a disk file that reads: foo $(bar) I would like to create this file using the cat command, e.g. cat <<EOF > baz.txt type_magic_incantation_here_that_will_produce_foo_$(bar) EOF The problem is the dollar sign. I have tried multiple combinations of backslash, single-quote, and double-quote characters, and cannot get it to work. 回答1: You can use regular quoting operators in a here document: $ cat <<HERE > foo \$(bar) > HERE foo $(bar) or you can disable

Is my shell broken?

℡╲_俬逩灬. 提交于 2020-01-07 11:29:05
问题 #!/bin/sh count=0 foo=0 echo "foo is $foo" while [ "$foo" -eq 0 ] && [ "$count" -lt 10 ]; do echo "inside while: foo is $foo" count=$((count+1)) foo=1 done echo "after while" You'd expect the script above to output the following, right? foo is 0 inside while: foo is 0 after while And it does on many other machines, like your own. But not mine ... foo is 0 inside while: foo is 0 inside while: foo is 1 inside while: foo is 1 ... (infinite loop) Am I doing something wrong, or am I missing

Is my shell broken?

℡╲_俬逩灬. 提交于 2020-01-07 11:27:41
问题 #!/bin/sh count=0 foo=0 echo "foo is $foo" while [ "$foo" -eq 0 ] && [ "$count" -lt 10 ]; do echo "inside while: foo is $foo" count=$((count+1)) foo=1 done echo "after while" You'd expect the script above to output the following, right? foo is 0 inside while: foo is 0 after while And it does on many other machines, like your own. But not mine ... foo is 0 inside while: foo is 0 inside while: foo is 1 inside while: foo is 1 ... (infinite loop) Am I doing something wrong, or am I missing

How to activate sh DTrace Provider?

此生再无相见时 提交于 2020-01-06 21:47:10
问题 I've found out about patches (and updates) for an x86 sh binary in 2007 to support sh DTrace provider. However I can't find any probes on OS X. I'm checking by: $ sudo dtrace -l | grep command-entry See: /bin/sh DTrace Provider at Oracle site (same article on blog) Maybe because my sh is the same as GNU bash? $ /bin/sh --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15) Where these probes were implemented, how I can find them or how I can activate them? Were there only