Use tee as follows: somecommand | tee This just copies stdin to stdout. Or uUse true or false. All they do is exit EXIT_SUCCESS or EXIT_FAILURE. somecommand | true Notice, every output to stdout from somecommand is dropped. Another option is to use cat: somecommand | cat ...
You just need to execute the following command: PYTHONPATH=./python python -m lex.gearman_worker ARGUMENT_2 ARGUMENT_3 ARGUMENT_4 < ARGUMENT_1 If that doesn't work then you may have to export the PYTHONPATH setting: export PYTHONPATH=${PWD}/python python -m lex.gearman_worker ARGUMENT_2 ARGUMENT_3 ARGUMENT_4 < ARGUMENT_1 The original arguments that you would pass to the script...
Remove the . lines: scratchpad(){ if [ $1 = run ]; then ruby ~/Programming/ruby/scratchpad.rb else open -a $1 ~/Programming/ruby/scratchpad.rb fi } In the shell, . is a builtin command in its own right, an alias for "source", which is used to read in a shell script and execute its commands...
save this in a file, e.g. makecsv.rc: #!/bin/sh echo Type,Count,Name x=0 for f in `cat` do x=`expr $x + 1` echo Def,u$x,$f done then run as: cat ../test.txt | ./makecsv.rc > ../test.csv if needed, you do chmod +x makecsv.rc The advantage is that the input/output file names are not hardcoded...
input,scripting,path,arguments,sh
The shell quoting is weird and not portable, better use : curl --remote-name-all \ --user use:passk \ "ftp://ftp.mozilla.org/pub/firefox/releases/$1/win32/en-US/Firefox%20Setup%20$1.exe" %20 is an URI escape for space (if not a typo in your post)....
Here's a sed version: /^Host_Alias/{ # whenever we match Host_Alias at line start : /\\$/{N;b} # if backslash, append next line and repeat s/$/,host25/ # add the new host to end of line } If you need to add your new host to just one of the host aliases, adjust...
If you look closely this is not the same path: tmp/trx//images/background/background_iphone5.png tmp/trx//images/background_iphone5.png --> tmp/trx//images/background/background_iphone5.png tmp/trx//images/background_iphone5.png This is the result output of find which finds 2 files with the same name in different subdirectories of /tmp. Just FYI, if you want to control how deep find can descend into subdirs, there's...
Digging deeper into the sources of the busybox that is running on the Linux I found out that the shell in busybox is calling signal(SIGHUP, SIG_DFL); during init. This resets the sighup handler to default. So the shell itself and the program it runs (provided with -c ...) are running...
linux,bash,redirect,command-line,sh
Solution based on the comment from "Zaboj Campula": if /bin/grep -q "^[[:space:]]/usr/bin/enigma2_pre_start.sh$" /var/bin/enigma2.sh then echo Unpatched > /tmp/enigma.sh /bin/sed -e 's/^\t\(\/usr\/bin\/enigma2_pre_start.sh\)$/\t\. \1/g' /var/bin/enigma2.sh -i pid=`/bin/ps -o ppid= $$` && /bin/kill $pid fi ...
This script will get called and passed a customer number. myEmailFinder "$CustID" I want to populate a variable based on the passed in customer number. emailAddr=$( myEmailFinder "$CustID") I want to pull an e-mail associated with that customer number and populate a variable with it. I would prefer this...
Simply tell the shell to wait until the children are all dead: child1.sh & child2.sh & child3.sh & wait rm -rf /home/bdata/batch/* ...
You need to use double quotes around "[email protected]" in order for it to work.
I answer my own question. What i was trying was to compile libvlc using osx instead of Linux. The problem was i don't know why but unzip was unable to extract the gradle.2.2.1.zip file so i thought i could do it using sudo but i was wrong because the execution...
You can refer to the STDIN Processing (http://amoffat.github.io/sh/#stdin-processing) and Redirection (http://amoffat.github.io/sh/#redirection) sections of the document. That said, your code: mysql < dump.sql should be equivalent to: dump_file = open("home/user/dump.sql", "r") sh.mysql(_in=dump_file) dump_file.close() ...
You can use this equivalent script in /bin/sh: if uname | grep -Eq '(QNX|qnx)'; then printf "what is the dev prefix to use? " read dev_prefix if echo "$dev_prefix" | grep -Eq '^[a-z0-9_-][email protected][a-z0-9_-"."]+:'; then ... fi fi ...
You can evaluate external shell script commands in current shell using source command, or .: source .color_rc or . .color_rc in your .bashrc...
You can readily combine your two lines: $ tr '[:upper:][:lower:]' '[:lower:][:upper:]' <<< "hEllo" HeLLO ...
Because as @Koiro told in the comment: Constants with a leading 0 are interpreted as octal numbers. you should enforce the 10based arithmetics db=0111 echo $db # Verify db is within the correct range if [[ 10#$db -lt 0 ]] || [[ 10#$db -gt 99 ]]; then echo "Invalid database"...
Whether you need just to pick up an API endpoint, you might use curl with respective CRUD action (POST/PUT/DELETE). Once you are stuck to wget, do the following: wget https://domain.com/url/key -o /dev/null -O /dev/null The above will redirect an output to nowhere preventing you directory from being garbaged....
php,linux,multithreading,shell,sh
To answer your question: You may start looking at pcntl_fork. Or you may check this. Basically, you are using the native fork to fork the long running process so your php frontend does not have to wait. If you're feeling adventurous, you may put your "job" (your request to this...
To clear up any confusion in my comment above, the following should work: echo -n "Enter id: " read id echo -n "enter startyear: " read startyear echo -n "enter endyear: " read endyear curl -i \ -X POST \ -H 'Content-Type: application/json' \ -d "{\"seriesid\":[\"${id}\"],\"startyear\":\"${startyear}\",\"endyear\":\"${endyear}\"}" \ http://api.bls.gov/publicAPI/v2/timeseries/data/ ...
linux,bash,find,sh,ubuntu-14.04
You could run this: find -mindepth 1 -depth -print0 | grep -vEzZ '(\.git(/|$)|/\.gitignore$)' | xargs -0 rm -rvf But simulate first what it would do: find -mindepth 1 -depth -print0 | grep -vEzZ '(\.git(/|$)|/\.gitignore$)' | xargs -0 echo rm -rvf Explanation: -mindepth 1 : it will exclude current directory -depth...
bash,command-line,scripting,sh
You can try $ dos2unix /home/pi/sh/test.sh and run it again....
Long-form (--foo) options are a GNU extension -- something present in GNU ls, but not present at all in the POSIX standard setting requirements for UNIX tools, so other versions of ls are not obliged to support these options. The entire word (foo) is meaningful in this case. This nomenclature...
The shell itself has no obvious facility for repeating a string. For just ten repetitions, it's hard to beat the obvious echo '##########' For repeating a single character a specified number of times, this should work even on a busy BusyBox. dd if=/dev/zero bs=10 count=1 | tr '\0' '#' Not...
The default behavior of DB2's EXPORT utility is to format any DECIMAL value with a leading positive/negative sign and pad it with leading zeros. To override this behavior, specify the DECPLUSBLANK and STRIPLZEROS options in your MODIFIED BY clause, or CAST the DECIMAL values to some other type in your...
Inspired by this question I've found this code to work: #!/bin/bash source `which virtualenvwrapper.sh` mkvirtualenv temp # This makes sure I'm not on the test virtualenv, workon temp # otherwise I can't delete it. deactivate doesn't # work for some reason rmvirtualenv test mkvirtualenv test workon test rmvirtualenv temp pip...
You need to use %'d instead of %s as the format specifier if you want thousands separators. Since you're passing the awk script on the command line, getting the quotes right can be tricky. With a hat tip to Ed Morton, here's one way to do it: #!/bin/sh awk -F,...
As @Aereaux pointed out you probably need inotify, available in Linux since 2.6.13. See http://en.wikipedia.org/wiki/Inotify There are inotify-tools available for command line usage as well. http://techarena51.com/index.php/inotify-tools-example/...
# file looks like: 466001004_cc_h5280w4080r120.jpg for file in *; do read basename w h <<< $(echo $file | awk -F_h '{print $1 " " $2}' | awk -Fr '{print $1}' | awk -Fw '{print $1 " " $2}') w=$(echo "$w 120 / p" | dc) h=$(echo "$h 120 / p"...
Don't use pipe to avoid a subshell being created in your script and use process substitution: #!/bin/bash x=1 y=1 while read -r tables; do while read -r id tolbox del_time; do ((y++)) done < <(mysql -e "SELECT id, tolbox, del_time FROM $tables WHERE deleted=0 ORDER BY create_time DESC LIMIT 0"...
recall that the form for a find command is find ${baseDir} -${options ......} args to opts. Your form is saying find tmp/$name -mtime +1 -type f # --^^^^^^^^^^ -- start looking in dir tmp/$name You probably want to say find tmp -name $name -mtime +1 -type f #---^^^^^ start looking...
The rule is outlined in the manual: Section Shell Operation. You'll read: The following is a brief description of the shell’s operation when it reads and executes a command. Basically, the shell does the following: Reads its input from a file (see Shell Scripts), from a string supplied as an...
I would pass a here document to stdin: ./script.sh install <<EOF y 2 1 n n EOF If you want it on one line, you can also use echo: echo -e "y\n2\n1\nn\nn" | ./script.sh install However, I prefer the here document solution since it is IMHO more readable....
When you define your array, you are using strings instead of variables: colr=(red blue green cyan purple yellow lgreen lblue lred lcyan) Should be: colr=($red $blue $green $cyan $purple $yellow $lgreen $lblue $lred $lcyan) ...
You can use %b in printf: func() { cmd="[email protected]"; printf "%s\n%b" "$cmd" "$cmd"; } Then call it as: func '%{NAME}\n\n' This will print: %{NAME}\n\n %{NAME} ...
Since you've put $command in quotes this prevents the shell from performing field splitting on it's contents, it's treated as one single word. Thus the name of the of command it tries to run is the full contents of $command including it's spaces and double quote characters. You could omit...
bash,sh,variable-assignment,short-circuiting
I guess you're trying to do this: #!/bin/sh S=0 T=0 numargs=$# printf "You passed %s arguments\n" "$numargs" check_param () { if [ "$1" = "$2" ]; then return 1 else return 0 fi } i=1 while [ "$i" -le "$numargs" ]; do current_arg=$1 shift case $current_arg in (-s) S=1 ;;...
Run it in the foreground, not as daemon. When it ends the script that launched it takes control and commits/push it
You can either declare a global flag that gets set inside the confirm function on a good answer, or you can use a return statement inside confirm that gets tested in a conditional in your while loop. There are other options too, like using a recursive call after testing the...
You will need to know a maximum length the numbers i trancodestotalsumt.txt can have or process the file twice to calculate it in the first pass. Assuming that you know the maximum width, replace printf("%14s Code %s%15s%" sq ".2f\n"," ",$1," ",$2) >> outfile with # vv--- here printf("%14s Code %s%15s%"...
Unless for some special reason you need arrays, don't bother yourself with arrays, simply do: for f in ../path/* do echo "==$f==" done Using @EtanReisner comments: #!/bin/bash FILES=(../benchmark/cfg/*) n=0 for f in "${FILES[@]}" do let n++ echo "Processing file($n from ${#FILES[@]}) ==$f==" done ...
Let's define our variables: a="abc pqr mno xyz" b="mno pqr xyz abc" Now let's define a helper function which puts the words in alphabetical order: sorted() { echo "$1" | sed 's/[[:space:]][[:space:]]*/\n/g' | sort; } Now, using our helper function, lets test for equality: [ "$(sorted "$a")" = "$(sorted "$b")"...
You can use indirect variable reference: test_var='foo bar baz' a='test_' b='var' c="${a}${b}" echo "${c}" test_var echo "${!c}" foo bar baz PS: You should avoid all uppercase variables in Unix to avoid collision with shell internal variables....
sed works better here: cat /proc/cmdline | sed -e 's/^.*root=//' -e 's/ .*$//' The first expression removes root= and everything before. The second one removes the next space and everything after....
It's not entirely clear what you want: if xyz.sh finishes in 3 seconds, do you want to wait an additional 17 seconds? Or do you want to interrupt xyz.sh after 20 seconds and make it produce output? If the latter: $ cat a.sh #!/bin/bash ./xyz.sh & i=${1-20} echo while test...
Assuming that IFS by default is set to space: # echo${IFS}a${IFS}b a b Tested on Solaris 10 sh....
Before the while loop, do this if (( $# == 0 )); then echo "you must specify one of -i or -a or -s" exit 1 fi or, after the while loop, you can do this if [[ $ifl != true && $afl != true && $sfl != true ]];...
See the discussion in the chat. The problem turned out to be a Unicode Byte Order Mark (BOM) encoded in UTF-8 as bytes 0xEF 0xBB 0xBF, which the shells didn't like. Removing that, and ensuring that the shell code will work with dash rather than bash, got things working correctly....
You could do ls -l . | awk '{print $1}', but you should follow the general advice advice to avoid parsing the output of ls. The usual way to avoid parsing the output of ls is to loop over the files to get the information you need. To get the...
Here is a simple Awk script to collect as many items of the same kind as possible on the same line. awk -v RS=',' -F : '{ gsub(/\n$/, "") } NF > 1 { r=(r ? r "," : "") $0; if (r ~ /([^,]*,){6}/) { print r; r=""; }...
\e is not recognized by POSIX sh (as mentioned by honzasp), but \033 is. GREEN='\033[32m' CLEAR='\033[0m' printf "${GREEN}testpassed${CLEAR}\n" Generally, it's safer to not expand parameters inside the first argument to printf (consider, for example FOO="hello %s"; printf "$FOO bar \n" baz;). However, this requires you to embed an actual escape...
Execute df -h, pipe the command output to grep matching "/dev/sdb1", and process that line by awk, checking to see if the numeric portion of column 5 ($5 in awk terms) is larger than or equal to 98. Don't forget to check for the possibility that it's over 98.
mkdir -p by itself provides the logic you want, so you could simply do: mkdir -p "$HOME/LOGS" && pushd "$HOME/LOGS" >/dev/null || exit mkdir -p creates the target directory if it doesn't already exists and then changes to it. Note that mkdir -p indicates success even if the target already...
Too bad you don't have a tclsh on busybox, it has a builtin string map command that would be ideal. Here's an implementation of that in awk and shell: #!/bin/sh code () { codemap="a yhWEm b UZltn c EfmN8 d cZKay e QkX8S f 8ejzg g dUTiB h hilDg i...
python,bash,shell,sh,travis-ci
You're using the bash feature extglob, to try to exclude the files that you're specifying. You'll need to enable it in order to have it exclude the two entries you're specifying. The python subprocess module explicitly uses /bin/sh when you use shell=True, which doesn't enable the use of bash features...
The output you showed for time echo lol | cat | wc -l does indeed require a time to be a shell builtin (actually something even more rare than a shell builtin: a keyword, like if and for.) There are a couple of flaws in your investigation. First of all,...
The location of the script is irrelevant. The thing that matters is the working directory of the process executing the script. The simplest solution really is to add aescrypt to a standard location like /bin or /usr/bin. If neither of those is acceptable, perhaps /usr/local/bin is an option. Otherwise, just...
sh is treating the bashism {1..10} as a string so for a in {1..10} sets a to the string {1..10} loops once then quits. You'd have caught that yourself if you'd used echo "$a" instead of echo 'a' as @CharlesDuffy suggested immediately when you posted the question. Hopefully you know...
Perl solution: perl -we 'for (@ARGV) { my ($n, $r) = /^([0-9]+)(.*)/; rename $_, sprintf("%0" . length($n) . "d", 1 + $n) . $r; }' *.mp3 The regular expression match extracts the number to $n and the rest to $r. $n + 1 is then formatted by sprintf to be...
I assume you are using while read because you want to do some stuff with the variables, not just printing them. If it was the case, simple awk would suffice. But if you want to have a bash variable with the content, you can do the following: You can set...
Quote the variable line and better to use read -r: while read -r line; do printf "%-20s\n" "$line"; done < file1.txt Test: while read -r line; do printf "%-20s\n" "$line"; done < file1.txt | cat -vte Steve Smith $ Thomas Muller $ Tim Cook $ Bill Gates $ ...
Something like this with grep: grep -vxf lines.txt data.txt > no_dupplicate_lines.txt Sample: AMD$ cat lines.txt Line2 Line4 AMD$ cat data.txt Line1 Line2 Line3 Line4 Line5 AMD$ grep -vxf lines.txt data.txt Line1 Line3 Line5 Print the lines that are not matching (-v) the exact lines (-x) from the file lines.txt (-f...
You can use awk and sort. cnt uses your numbers in column 1 $1 as an index. Adds ++ 1 to value of array index $1 on each row. Pipe (|) to sort. sort column 2 (-k2) in reverse (-r) awk '/[0-9]/ {cnt[$1]++}END{for(k in cnt) print k,"- " cnt[k]}' file.txt...
How old is the documentation? Usually, this sort of thing (often referred to as 'the exec hack') was recommended before /bin/env was common, and this was the best way to get the functionality.
Well, I just realized the rather obvious (using recursion): loop() { for file in $1/**; do >/dev/null if [ -d "$file" ]; then loop "$file" elif [ -e "$file" ]; then echo $(owner "$file")"\t$file" fi done } And it seems to be working alright. ...
There is indeed a race condition, in that an adversary could potentially access /tmp/shadowcopy between the script creating it and the script setting its permissions. However, if indeed the script creates the file, then its initial permissions will be governed by the effective umask. If that allows files to be...
You don't really need to loop 2 variables, just use 2 BASH arrays: input=("File1" "File2" "File3") output=("OutFile1" "OutFile2" "OutFile3") for ((i=0; i<${#input[@]}; i++)); do echo "Processing input=${input[$i]} and output=${output[$i]}" done ...
in the loop, test if file exists before calling a program operating on that file: for i in $(seq 0 100); do INPUT=c2.$(($i*40+495)).bin test -e $INPUT && ./f.out $INPUT c2.avg.$(($i*40+495)).txt done This way the ./f.out ... will be executed only for existing input files. See man test for details. BTW,...
Most likely a typo : [[ "$VALUE" == "v" ]], this should be [[ "$FLAG" == "v" ]] ...
It seems that I was getting random additions of ^M whilst transferring via ftp due to writing the scripts in Notepad++. They weren't added to every revision of code though, so it wasn't a consistent thing. They were however stopping start.sh from running without giving any real notion as to...
If you want to print a unicode character in /bin/sh (which isn't required by POSIX to support \u sequences), either embed it literally in your script or break it down into its component bytes and print those individually. For the snowflake symbol used in the question: printf '\342\235\204' Now, how...
In a posix shell, 0 means success and other values means failure. When we use a command in a logical expression, we are testing it's exit status. We can use $? to check the last exit status. Experimenting: $ true $ echo $? 0 $ false $ echo $? 1...
How about : find . $(printf "! -name %s " $(cat exclude_list_file)) -exec process {} \; ...
Your grep and cut should be working but you can use awk and reduce 2 commands into one: while read -r id; echo "$id" done < <(awk -F '\\.' '/something/{print $1}' file.txt) To populate an array: ids=() while read -r id; ids+=( "$id" ) done < <(awk -F '\\.' '/something/{print...
wget expect can be tricky to work with so I'd prefer to use GNU Wget as an alternative. The following should work as long as you don’t have any spaces in any of the arguments. for v in "${files_to_download[@]}" do ftp_file="${v}.bz2" wget --user=${USER} --password=${PASSWD} ${HOST}/${ftp_file} done Request multiple resources using...
django,bash,cron,sh,ubuntu-14.04
You need to run it with: bash parser.sh not sh parser.sh. If your script is written for bash, you shouldn't try to execute it with sh. Every syntax of your script may not meet the standards of sh Bourne shell. Change the cron job command to: */15 * * *...
You can use: a='foo' b='bar' file="$a"$'\n'"$b" echo "$file" foo bar Or use print -v: unset file printf -v file "$a\n$b" echo "$file" foo bar ...
This is close to optimal -- but drop the eval. executeToVar() { local varName=$1; shift; printf -v "$1" %s "$("[email protected]")"; } The one problem this formulation still has is that $() strips trailing newlines. If you want to prevent that, you need to add your own trailing character inside the...
A common arrangement is to write your scripts so that programmatic operation is convenient. In concrete terms, that means that your script should return a zero exit code on success, nonzero otherwise. Then what you ask for is a simple matter of script1 && script2 or in more complex cases...
I have solved the problem by executing the commands in a subshell like this: if ! (pwd && ls && mkdir /opt/test/); then echo "failure" else echo "success" fi The exit status of the subshell is returned and tested by the if statement....
A simplistic approach, assuming these are all in the current directory: for f in *actual_*.png; do mv "$f" `echo $f | sed "s/actual_[^/]*\.png$/expected.png/"` done ...
I would do this in awk. But as Aaron said, it will require reading the input twice, since the first time you hit a particular line, you don't know how many other times you'll hit it. $ awk 'NR==FNR{a[$1]++;next} {print a[$1],$0}' inputfile inputfile This goes through the file the first...
You can't (easily) convert an argument list to a string in a way that it can be converted back to a list. Fortunately, you rarely actually need to do that. It's not clear to me exactly what your requirements are, but here's a simple script which seems to demonstrate the...
To get the correct result with the least change to your command, try: partitionno=$(echo "$new" | sed "s|$old||g") There are two key points here: Shell variables are not expanded inside single quotes. So '$old' remains as the original four characters: $, o, l, and d. For the shell variables to...
the quotes are for your shell where you typed the command line, they should not be included when programatically launching an app just make this change and it will work: command2 := "pwd && pwd" // you don't want the extra quotes ...
I don't know if you are aware of the crossfade_cat.sh script offered by sox. You could just use it successively: ./crossfade_cat.sh 1 440.wav 660.wav auto auto && ./crossfade_cat.sh 1 mix.wav 880.wav auto auto Or if you want to crossfade a high number of wav files, to use all files in...
This will print a dot to the screen every second. Add these lines just before the first snmpwalk command. while true; do echo -n . ; sleep 1 ; done & pid=$! #do time consuming tasks here Then to stop printing the dots, add this line just after the last...
On my Linux system, I can simply do $ sleep 0.1 and it sleeps for 0.1 seconds. The sleep here lives in /usr/bin/sleep. I don't know which other unix-like systems support that, though....
sh,double-quotes,single-quotes
When you build a command, delay the interpolation and use eval to execute it. HOSTNAMES='host1, host2' cmd_options='' if [ "$HOSTNAMES" != "" ]; then cmd_options+='--hostnames "$HOSTNAMES"' fi eval "prog $cmd_options" A better solution is to use an array. HOSTNAMES='host1, host2' cmd_options=() if [ "$HOSTNAMES" != "" ]; then cmd_options+=(--hostnames "$HOSTNAMES")...
The character to allow a command to run in the background is &, not $. epiphany --new-tab www.google.de > /dev/null 2>&1 & ...
Following up on the comment, the syntax for initializing indexed array values in BASH is: array=( element1 element2 etc... ) In your case you were simply assigning the result of the command substitution to the array with: ARRAY=$(ls files-0/var/log/) (which assigned the return of ls files-0/var/log/ to a variable named...