The tag has no wiki summary.

learn more… | top users | synonyms

4
votes
3answers
101 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
53 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
52 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
34 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 ...
2
votes
2answers
58 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
59 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
23 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
80 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
139 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 ...
1
vote
1answer
74 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
115 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
25 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 ...
1
vote
1answer
630 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
414 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
55 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
851 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
155 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
1k 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 - ...
0
votes
1answer
303 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
146 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
64 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
149 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
81 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
98 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
955 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 ...
2
votes
3answers
141 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
259 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
183 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
97 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
138 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
774 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
421 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
385 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
892 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
312 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
2k 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 ...
4
votes
1answer
848 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
278 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 ...
5
votes
3answers
601 views

How to generate new var names on the fly

I'm trying to generate dynamic var names in a shell script to process a set of files with distinct names in a loop as follows: SAMPLE1='1-first.with.custom.name' SAMPLE2='2-second.with.custom.name' ...
13
votes
1answer
606 views

Why does variable expansion without $ work in expressions?

#!/bin/bash VALUE=10 if [[ VALUE -eq 10 ]] then echo "Yes" fi To my surprise, this outputs "Yes". I would have expected it to require [[ $VALUE -eq 10 ]]. I've scanned the CONDITIONAL ...
2
votes
2answers
447 views

pure shell complex substitution in variable

However it may be impossible, I hope I'm just bad man reader =) Is there any way to substitute text in variables on several patterns at time or even using back reference? For example, I have ...
6
votes
2answers
975 views

Dereference concatenated variable name

I can do this, but it requires making a string of the variable then dereferencing it. Is there any way to shorten it to a simpler statement? #!/bin/bash FRUITS="BANANA APPLE ORANGE" ...
7
votes
1answer
454 views

Why is bash extended-globbing variable substitution acting at the byte level?

I thought that bash variable substitution and globbing worked at character resolution, so I was rather surprised to see it acting at the byte level. Everything in my locale is en_AU.UTF-8 When ...