Menu
  • HOME
  • TAGS

Pipe that does nothing

bash,sh,ksh,nop

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 ...

Convert shell script command to command line

python,shell,sh

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...

“Filename argument required” warning when running shell command from bash_profile

bash,unix,terminal,sh

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...

Bash Script to generate csv file from text

bash,shell,sh,export-to-csv

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...

Bourne shell, script to compile file path then to pass it to a program

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)....

Validating file records shell script

linux,bash,shell,unix,sh

Simple awk: awk -F: '/^rec/{a[$1]++}END{for(t in a){if(a[t]!=7){print "Some error for record: " t}}}' test.rc ...

How to append entry the end of a multi-line entry using any of stream editors like sed or awk

linux,bash,awk,sed,sh

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...

Getting duplicate output

bash,scripting,sh

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...

SIGHUP signal handler reset to default when using system() on embedded linux with busybox

c,linux,sh,busybox

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...

Redirect stdout using exec in subscript

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 ...

Storing data in shell

shell,sh

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...

How to run shellscript parallely like java thread

shell,unix,sh

Simply tell the shell to wait until the children are all dead: child1.sh & child2.sh & child3.sh & wait rm -rf /home/bdata/batch/* ...

Arguments with spaces are seen as separate arguments and not as one argument [duplicate]

linux,bash,shell,sh

You need to use double quotes around "[email protected]" in order for it to work.

Environmental variable is empty into shell script but not in shell

android,bash,shell,sh,libvlc

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...

Python Sh Library for MySQL dump import using output redirection (<) pipes

python,mysql,pipe,sh

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() ...

How to write and match regular expressions in /bin/sh script?

regex,shell,unix,sh

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 ...

Can you import variables into .bashrc?

bash,sh,.bash-profile

You can evaluate external shell script commands in current shell using source command, or .: source .color_rc or . .color_rc in your .bashrc...

BASH convert uppercase to lower case and vice versa at same time

bash,shell,sh

You can readily combine your two lines: $ tr '[:upper:][:lower:]' '[:lower:][:upper:]' <<< "hEllo" HeLLO ...

Bash if number greater then failing

bash,sh

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"...

Unwanted text file is creating while calling a URL through Cron

ruby-on-rails,ruby,cron,sh

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....

PHP5, Shell_exec waiting for spawned linux shell tasks to finish

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...

Bash Script_ Inserting variable read from read command into command

linux,bash,curl,sh

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/ ...

remove everything exept for .git directory and .gitignore on linux

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...

Syntax error: “fi” unexpected (expecting “then”) in bash script

bash,command-line,scripting,sh

You can try $ dos2unix /home/pi/sh/test.sh and run it again....

BASH : Difference between '-' and '--' options

linux,bash,shell,sh,ls

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...

How to repeat a character in Bourne Shell?

unix,sh

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...

db2 - export into File

unix,db2,sh

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...

Why does using virtualenv commands in .sh file give “command not found”? [duplicate]

osx,bash,sh

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...

Format a number with thousands separators in shell/awk

awk,sh

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,...

How can I detect if some file in a subdir changed?

linux,console,sh

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 name contains pixel dimensions that need to be converted to inches

bash,sh,exiftool

# 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"...

Get variable outside WHILE in SHELL BASH script

mysql,bash,shell,sh,do-while

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"...

error to delete files older than 1 day form csv list

sh,ksh,aix

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...

Why doesn't ${#$2} work?

bash,sh

The parameter name is 2, not $2. if [ ${#2} -lt 25 ]; then ...

Bash quirk when passing string from command line

bash,shell,scripting,sh

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...

Bash script - Auto fill answer

linux,bash,shell,sh,auto

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....

Getting value from function, use that value to get colored output in shell

shell,sh,zsh,zshrc,oh-my-zsh

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) ...

POSIX Shell backslash confusion

shell,sh,backslash

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} ...

Running stored command with environment variables

sh

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...

sh boolean short circuit variable assignment

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 ;;...

How can I run a docker container and commit the changes once a script completes?

bash,docker,sh,commit

Run it in the foreground, not as daemon. When it ends the script that launched it takes control and commits/push it

Confirming Shell Script Input

bash,shell,sh

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...

how to align the decimal values in a ksh script report

shell,awk,sh

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%"...

Length of array of files not correct in shell

shell,sh

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 ...

Disregard word order when comparing two variables

shell,unix,sh

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")"...

Get value of variable with the aggregated values of other variables [duplicate]

bash,sh

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....

How to extract value of root variable from kernel commandline

linux,bash,sh,busybox

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....

How to set the timer in shell

shell,sh

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...

Printing a “Hello World” in bourne shell without directly using white space char

linux,sh

Assuming that IFS by default is set to space: # echo${IFS}a${IFS}b a b Tested on Solaris 10 sh....

Checking for lack of flags in bash

bash,scripting,sh,getopts

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 ]];...

Strange issue relating to shell script files

linux,bash,shell,unix,sh

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....

cut text file and get the first field bash

grep,sh,cut

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...

Bourne shell: split string according to multiple criteria (iptables multiport limitation)

string,shell,split,sh

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=""; }...

ANSI escapes don't work in `printf`

bash,printf,sh,ansi-colors

\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...

How to execute command when df -h return 98% full

linux,shell,sh

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.

Linux shell file. mkdir and pushd commands not doing what I'd like

linux,shell,sh,mkdir

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...

Shell command for character replacement

linux,shell,sh

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...

Passing a pre-defined variable from shell script to shell script in Linux

linux,bash,shell,variables,sh

Perhaps, what you need is to pass the parameter through the command line arguments, i.e.: ./example.sh $patientid in the main script and patientid=$1 in the example.sh script....

Error in check_call() subprocess, executing 'mv' unix command: “Syntax error: '(' unexpected”

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...

How can `time` control other processes trough a pipe?

time,pipe,sh

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,...

Running an executable by calling it in a .sh file

bash,sh

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...

for x in {1..10} in shell script runs only once

linux,ubuntu,awk,sh

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...

Increment of multiple file prefixes?

bash,sh

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...

Split lines on separator but just two slices

bash,shell,awk,sh

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...

Padding a files with n number of spaces at the end of the line

shell,unix,sh,padding,aix

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 $ ...

how to deletes line from a text file that are taken from another file [duplicate]

shell,awk,sed,grep,sh

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...

Order lines by number of occurrences

list,shell,sh

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...

Why does Scala use a reversed shebang (!#) instead of just setting interpreter to scala

bash,scala,sh

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.

Portable solution to loop through a directory recursively in bash 3.2

shell,unix,sh,portability

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. ...

sh script vulnerability in Linux

linux,security,sh

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...

Loop two variables through one command in shell

bash,shell,sh

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 ...

shell command to skip file in sequence

shell,sh

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,...

Testing truth/falseness in bash script

osx,bash,shell,sh

Most likely a typo : [[ "$VALUE" == "v" ]], this should be [[ "$FLAG" == "v" ]] ...

Issues with Screen - Running Minecraft in a while loop through a screen session

bash,while-loop,sh,minecraft

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...

Unicode characters in /bin/sh VS /bin/bash

bash,unicode,sh,chars

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...

How to split and iterate substrings by delimiter in BOURNE SHELL?

string,shell,loops,split,sh

Try: OIFS="$IFS" IFS=: MY_ROOTS=/f/o/o:/b/a/r:/e/t/c for my_root in $MY_ROOTS; do # your code here with $my_root done IFS="$OIFS" ...

evaluation of logical expression chain in /bin/sh

sh

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...

BASH find file names but skip a list of file names

bash,printf,sh,filenames

How about : find . $(printf "! -name %s " $(cat exclude_list_file)) -exec process {} \; ...

how to extract grep and cut into a bash array

linux,bash,shell,sh

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...

Linux - sh script - download multiple files from FTP

linux,ftp,sh

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...

source: not found error while running shell script on ubuntu 14.04

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 * * *...

Printing a newline

bash,sh

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 ...

How do I indirectly assign a variable in bash to take multi-line data from both Standard In, a File, and the output of execution

linux,bash,shell,scripting,sh

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...

Is it possible to check the output of previous step in the same script

bash,sh

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...

How to negate multiple conditions in the Bourne shell

shell,sh

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....

Linux Rename Multiple Files At a Shell Prompt

linux,sh

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 ...

Sort and counting a column without uniq in bash

linux,bash,sorting,count,sh

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...

Pass command line arguments from bash script to program verbatim, with escaping

bash,unix,sh

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...

Find and replace in shell script (special characters)

shell,sh

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...

os.Exec and /bin/sh: executing multiple commands

bash,shell,go,sh

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 ...

Cross fading several audio files using sox

bash,audio,sh,sox,cross-fade

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...

Showing progress as shell script runs

shell,sh,snmp,net-snmp

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...

How to limit the CPU usage of a dash loop that listens for a filesystem change?

loops,sh,cpu-usage,dash

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....

Shell script to build CLI args for a PERL script

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")...

Start epiphany browser from bash and continue script

linux,bash,shell,sh

The character to allow a command to run in the background is &, not $. epiphany --new-tab www.google.de > /dev/null 2>&1 & ...

Error on retrieving array length in bash

bash,shell,sh

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...