The tag has no wiki summary.

learn more… | top users | synonyms

0
votes
1answer
35 views

Bash Brace Expansion & Variables [duplicate]

I have a find command: find Directory/{Alpha,Bravo,Charlie} arg1 arg2 I want to replace Alpha,Bravo,Charlie with $find_dir find Directory/{$find_dir} arg1 arg2 however the latter expands to ...
6
votes
2answers
197 views

Piping bash string manipulation

I've read some other piping bash string manipulation questions but they seem to be specialized applications. Essentially, is there a way to do the below simpler? instead of $ string='hello world'; ...
1
vote
1answer
49 views

Append to PATH-like variable without creating leading colon if unset

I need to append a directory to PKG_CONFIG_PATH. Normally, I would use the standard export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:$(pyenv prefix)/lib/pkgconfig but PKG_CONFIG_PATH has not been ...
2
votes
2answers
60 views

Environment variable not expanded inside the command line argument

I have a file user-pid.out2 which has "usernumber" and "process id" as two columns. based on usernumber I want to find corresponding process id. the first two lines below does not show the output ...
1
vote
2answers
55 views

assign output of a c program to a shell variable: token error

I have a shell script to run several times a .c program ('switch') which admit 3 input paramenters. I want to run the program 4 times passing values {4,16,32,64}, and for parameters ...
3
votes
1answer
53 views

Service script calls another script with variables

I have a simple service script tomcat7 in /etc/init.d/ to start and stop my app server (tomcat) under the tomcat user. On RHEL6. #!/bin/bash # description: Tomcat Start Stop # processname: tomcat # ...
1
vote
1answer
43 views

Replacing shell variable names in another variable

I've been wrestling with bash variable substitution for a while now and can't figure this out... I have a variable with a command template: CMD_TMPL='sudo -u ${USER_NAME} ${USER_HOME}/script.sh' ...
1
vote
1answer
61 views

Expand shell variable without globbing

I want to check whether an input string refers to a file name - not a wildcard string like *.txt. This doesn't work: if [ -f "$1" ]; Because $1 gets expanded to *.txt, which gets expanded to, say ...
2
votes
1answer
56 views

Parameter substitution and error messages: suppressing line numbers etc

Here is my example file: !/bin/bash # argument-one # Is first argument missing? # First method [[ "$1" == "" ]] && echo "Usage: $(basename $0) filename"; exit 1 # Second method # ...
5
votes
1answer
2k views

Executing commands with ssh and shell script using variables on a remote machine

I'd like to execute a command and script located on a remote machine with a script on a local machine. I know it's possible to execute these kind of commands with ssh, so I made: #!/bin/bash ssh ...
0
votes
1answer
88 views

Copy selected files had subtitutions in name

I have some folders: oldA with A_1.aaa, A_2.aaa, A_1.bbb, A.def, A.ghi oldB with B_1.aaa, B_2.aaa, B_1.bbb, B.def, B.ghi and so on and need to copy them to another folder with selection. I want ...
0
votes
1answer
55 views

Special Parameter query - multiple used to obtain command name? [duplicate]

In a uni text provided us to cover bash scripting, the following variable assignment has got be stumped and I've yet to get an answer back from anyone, hence hopefully someone on here can help. ...
5
votes
3answers
915 views

How can I pass argument stored on a variable to WGET

I'm writing a bash script that extensively uses wget. To define all common parameters in one place I store them on variables. Here's a piece of code: useragent='--user-agent="Mozilla/5.0 (Windows NT ...
2
votes
2answers
196 views

Bash parameter expansion - greedy versus non-greedy

It's a bit of a contrived example but here goes: Say I have a variable 1.2.3.4 containing version information and need to replace the .4 at the end with .5 version=1.2.3.4 echo ${version%.*}.5 ...
3
votes
1answer
375 views

variable expansion within command substitution over SSH bash 4.X

I want to do this ssh ${w100user}@web100 'ls -l "$(grep "${1}" /etc/pure-ftpd/pureftpd.passwd|cut -d':' -f6)"' Which obviously performs an ssh session to server web100 as w100user and then greps ...
-3
votes
1answer
95 views

why does the dollar sign cause this command to be executed?

test_script.sh: #!/bin/sh D1="$(dirname $0)" echo $D1 D0="(dirname $0)" echo $D0 What I type on the command line: $ ./test_script.sh Output: . (dirname ./test_script.sh) What significance ...
3
votes
2answers
141 views

What is the effect of “${(@f)…}” in Zsh?

I ran into a Zsh script and wanted to know its meaning. In the scripts below there is ${$(@f)$(egrep "$2","$file")} expression. From what I searched, @ is to use represent all positional parameters, ...
0
votes
1answer
110 views

Unknown syntax in /etc/rc.d/init.d/functions

Looking at the file /etc/rc.d/init.d/functions, I can see the following is declaring a number of variables as local variables. However, why are the variables killlevel and pid_file have an equal sign ...
1
vote
1answer
35 views

Where can I find documentation on shell script syntax for using a regex within a variable construct?

I'm debugging a shell script (which I didn't write) that contains this loop: read line < "$pid_file" for p in $line ; do [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p" done ...
-2
votes
1answer
92 views

how do I make a $VAR empty so it don't effect the command line argument and still be within that argument?

This is the basic setting for hsetroot for it to work: hsetroot -center /path/to/image/ - setting the wallpaper with just that the picture. To use these options, just one has to be place within the ...
0
votes
1answer
2k views

How to reassign new values to array elements?

I'm trying to figure out like three or four things at the same time.The most I need help with is how to get the greatest number in all the files that I have created on a prior run of my script, that ...
2
votes
1answer
107 views

What does the expression ${MYVAR:+-x} mean in bash?

In a bash script I cannot post here I see the following expression: ${MYVAR:+-x} I understand the meaning of expressions like ${MYVAR:+OTHERVAR} and ${MYVAR:-OTHERVAR}, but an expression with both ...
0
votes
1answer
199 views

Why does a working standalone nested function/script not work inside a larger script? [duplicate]

The following (nested) function/s function hpf_matrix { # Positional Parameters Matrix_Dimension="${1}" Center_Cell_Value="${2}" # Define the cell value(s) function hpf_cell_value { ...
0
votes
0answers
26 views

Variable Substitution in sed [duplicate]

I have this script and I need to count the lines inside a file, then pass the number of lines counted to a for loop so that I can get the contents of each line and put it in a variable. My question ...
2
votes
1answer
2k views

bash: export: `--wait': not a valid identifier

When I run git-sh from my terminal it works fine. But I get the following warning. bash: export: `--wait': not a valid identifier What is this and how do I get rid of it?
2
votes
2answers
2k views

bash ${VAR//search/replace} and weird regex behaviour

I am trying to do some searching and replacing on a variable using the ${VAR//search/replace} parameter expansion. I have a pretty long and evil PS1, that I want to work out the size of after ...
0
votes
1answer
137 views

How achieve variable indirection (refer to a variable whose name is stored in another variable) in tcsh

I'm trying to do the following: set a = kitten set temp_kitten = purr echo ${temp_$a} I want the echo command to return "purr". The overall idea is that I have a bunch of variables in an array and ...
2
votes
2answers
4k views

Passing a variable to sed

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt ...
1
vote
1answer
348 views

Trouble with mv and adding the date

I want to be able to move $oldfile to my backup folder and add the date to the file name. So I tried this... mv $oldfile /home/u0146121/backupfiles/$oldfile_$(date +%F-%T) This just gives me this ...
1
vote
1answer
3k views

Adding a time stamp when moving a file in bash [duplicate]

#!/bin/bash while read server <&3; do #read server names into the while loop if [[ ! $server =~ [^[:space:]] ]] ; then #empty line exception continue fi echo "Connecting to - ...
1
vote
2answers
2k views

using bash script to output new script: need mixture of variables to be replaced and not replaced

I'm having a problem with bash variable substitution. Here's a silly example of what I am trying to do. I need to output a new script from a bash script. A line (see echo in my example) has a mixture ...
0
votes
1answer
598 views

when to use double quotes with a variable in shell script? [duplicate]

I am in a confusion with what is meant by the double quotes referring to a variable. For example following two scripts gives the same output. What is really meant by the double quotes? Script1 ...
1
vote
3answers
75 views

Variable scope in multiple pipes

I was trying to do something following, find . -name "*.dat" | get the basename of file | move filename returned by first command to basename returned by second command To give a concrete example, ...
2
votes
3answers
286 views

Can I reload variable in a watch command?

Part of my job involves some data handling. One of the tasks is to 'flatten' a set of directories (which we'll call Dir for now), and copy them to a new location called DirFlat. This can take a long ...
0
votes
1answer
98 views

Colon breaks the variable subsitution [closed]

I am trying to lookup some C functions so that I could debug while using strace. So I setup a bash function to look it up in firefox (or links), but the substitution falls apart with : and escaping ...
3
votes
1answer
106 views

Different behavior of $() and `` [duplicate]

% PATH="MYPATH" % VAR="PATH" % echo $(eval echo \$$VAR) MYPATH % echo `eval echo \$$VAR` 5707VAR ^^ This is the process number. I thought those two were exactly the same, but obviously there are ...
4
votes
4answers
2k views

Double and triple substitution in bash and zsh

Follow-up to the background part in this question. In bash I can use {!FOO} for double substitution, in zsh ${(P)FOO}. In both, the old-school (hack-y) eval \$$FOO works. So, the smartest and most ...
3
votes
3answers
252 views

${!FOO} and zsh

${!FOO} performs a double substitution in bash, meaning it takes the (string) value of FOO and uses it as a variable name. zsh doesn’t support this feature. Is there a way to make this work the same ...
2
votes
1answer
306 views

shell variable in awk is not being passed to all the lines but just for the very first line of input?

inputfile:is2.txt 10.39.5.41,A1,B1 10.39.5.41,A2,B2 10.39.5.41,A3,B3 10.39.5.41,A4,B4 10.39.5.41,A5,B5 10.39.5.41,A6,B6 script : #!/bin/bash second_column="OOOOOOO" # OOOOOOO will be added to ...
0
votes
2answers
225 views

Shell script parameter substitution

I have seen a line of shell script as follows: local soft_upgrade=${3:-false} What does this mean? I don't know what 3:-false means.
0
votes
1answer
200 views

Combining parameter expansion with modifiers in zsh

Say I have the following $f1=/some/path $f2=/some/subpath $f3=/some/other/subpath If I try: test1=${$f1/$f2/${f3:t}} zsh complains with bad substitution. However: test2=${f3:t} works well. ...
2
votes
2answers
188 views

Picking a random file from each subfolder

Inspired by the accepted answer to this thread: List X random files from a directory, I tried to put together two lines that would pick one file from each subfolder of my current directory, with no ...
2
votes
3answers
1k views

Substitute placeholders in template

Say I have a shell configuration file config like this: HOST=localhost PORT=8080 Now I have a template template like this: The host is <%= @HOST %> The port is <%= @PORT %> How do I ...
0
votes
1answer
665 views

Unable to loop through cURL command

I am able to execute individual cURL commands using, curl -u user:password -v -XPOST -H 'Content-type: text/xml' -d '<featureType><name>quadrella_indica</name></featureType>' ...
0
votes
4answers
588 views

Bash Globbing Variable Substitution? [duplicate]

Possible Duplicate: Batch renaming files I want to rename files using their existing name as a base for the new one. So if I can ls these files with ls blue*+(.png) I'd want to rename ...
1
vote
1answer
2k views

Variable Substitution in Awk Print Statement -v

I've spent over an hour poking at this. It can't be this hard... I want to print a column of data from one file to another file. The column I want to print is dependent on what is passed in and stuff ...
1
vote
1answer
366 views

Shell variables not working?

I'm trying to store the date in a variable ($DATE) so I can use it later, but it doesn't seem to work. See anything wrong? DATE=$(date +"%Y-%m-%d %R") sudo mysqldump -u root -pnotgivingyoumypassword ...
5
votes
4answers
6k views

Use a variable reference “inside” another variable

I'm sure it is relatively simple, I just don't know how to do it. #!/usr/bin/ksh set `iostat` myvar=6 I want to something like echo ${$myvar} which i want interpreted as ${$myvar} -> ${6} -> value ...
5
votes
1answer
1k views

Variable substitution with an exclamation mark in bash

I have the following lines in my .cfg bash script file DDF_SOURCE="siebel_DATA_DATE_FORMAT" DATA_DATE_FORMAT=${!DDF_SOURCE} how is ${!DDF_SOURCE} evaluated? It would be !siebel_DATA_DATE_FORMAT, ...
1
vote
3answers
471 views

Reevaluate the prompt expression each time a prompt is displayed in zsh

I'm adjusting my zsh prompt, based upon the dallas theme and the dstufft theme from oh-my-zsh. I love how dallas has various sections of the prompt contained in variables, which makes it much easier ...