The tag has no wiki summary.

learn more… | top users | synonyms

2
votes
2answers
41 views

bash + how to define array variable with instance number

Is it possible to define variable that is called for example machine1 as machine$counter ( while counter=1 ) ? For example, I created the /tmp/config.txt file and set the machine1 as array: $ more ...
1
vote
1answer
33 views

Passing variables to range patterns in awk

I'm trying to use range patterns in awk: grep -a volume somefile | awk '/^Apr 25 23:44:04*/,/^Apr 26 12:44:01*/ {print}' This works fine, but when I try to execute it by putting the date and time ...
2
votes
1answer
36 views

Expand variable in brace expansion [duplicate]

I am trying to enumerate a range of integers using a variable but having some trouble. When I type echo {1..5} I get 1 2 3 4 5 However, when I type a variable, I am unable to get the ...
0
votes
1answer
24 views

need help with inserting variables in a file path on GNU linux (SLES 11)

I am tryin to insert 3 variables to build a path, but unable to get it . I am trying the below log_path="/vol02/logs/$dname/logs/103602_$msname/${msname}_start.log" dname=cfp msname=cfp003 i get ...
4
votes
1answer
57 views

How to make sure the $var variable in expanded in “$varsomething”?

I'm trying to run something like this for n in 1 2 3 4 5 6 7 do run_this_command whatever.$nx$n.in done The files are named as whatever.1x1.in, whatever.2x2.in, ...
3
votes
3answers
213 views

Variable not expanding inside another variable bash

I am reading a csv file in bash script as follows: resource='/data/bscs/' while IFS='|'read seqid fname fpath do echo "FILENO: $seqid" echo "FILENAME: $fname" echo ...
0
votes
2answers
105 views

Expect Scripts - Reading from Files and Accepting User Input

How can I write an "Expect" script to: iterate over a list of IP addresses and log in to each to perform commands (like in a BASH for loop). Right now I just copy/pasted the few lines that are my ...
1
vote
1answer
75 views

awk with variables in condition and in output redirection file

I would please like some help with this command because I didn't find anything in documentation that can cover everything I want. I have some variables that are global, so I would prefer to keep them ...
4
votes
3answers
44 views

Can command substitution be nested in variable substitution?

I would like to use variable substitution on a particular string that I access via a command. For example, if I copy something into my clipboard, I can access it like this. $ xclip -o -selection ...
2
votes
1answer
37 views

Running a constructed command from bash script

I constructed a command like this in a bash script a="my_cmd"; a="$a --verbose"; echo $a; $a; It works and executes my command correctly. But when I add an environment variable to the mix it ...
0
votes
2answers
65 views

Multiple variable expansion modifiers in the same expression

Why does the following idiom not work in bash 4.1.0? if [[ "${FUNCNAME[*]:1/$FUNCNAME/}" != "${FUNCNAME[*]:1}" ]] Here it is in context... function isCircularRef_test () { # ### Seems like ...
1
vote
2answers
58 views

Why does zsh allow name to be null in ${name:-word}?

From zsh documentation: ${name-word} ${name:-word} If name is set, or in the second form is non-null, then substitute its value; otherwise substitute word. In the second form name may ...
2
votes
2answers
25 views

variable substitution in CLI and for loops

I am pretty sure this has been asked already in some form, I just cannot come up with a good find to search it. I want to have a script that do things N times and to which I can pass as a variable ...
2
votes
3answers
161 views

Print file name extension using -exec in find

I am playing around with -exec flag of find command. I am trying to use the flag to print the extension name of files, using a fairly new Linux distribution release. Starting simple, this works: ...
2
votes
3answers
208 views

Variable expansion in Bash

I tried the following commands variable='one|name' echo $variable The output is one|name whereas echo one|name gives an error No command 'name' found. This is reasonable because bash treats | as ...
1
vote
0answers
95 views

bash - expect and variables

I have the followin: while read line; do userinfo=$(echo $line | sed 's/@/,/') IFS=',' read -a address <<< "$userinfo" userid="${address[0]}" domain="${address[1]}" ...
1
vote
1answer
80 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
523 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
82 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
240 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 ...
2
votes
2answers
115 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
170 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
65 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
116 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
76 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 # ...
7
votes
1answer
7k 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
143 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
68 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
2k 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
361 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
646 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
113 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
204 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, ...
1
vote
1answer
156 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
42 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
95 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
5k 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
135 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
297 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
3k 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?
3
votes
2answers
3k 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 ...
1
vote
1answer
226 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 ...
3
votes
2answers
9k 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
608 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
6k 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
1k 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
93 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
435 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 ...