Questions tagged [variable-expansion]

Evaluating or expanding a variable to get its value. Depending on the language, a variable may be expanded one or more times.

246 questions
0
votes
2 answers

bash - parameter substitution until line break

I have a .txt file that contains a text like this : {remove}Some text in line 1 Some text in line 2 Some text in line 3 {remove} Some text in line 4 With Parameter expansion how can I delete all lines that contain the special tag {remove} ?? I…
GabryRome
  • 95
  • 1
  • 3
  • 8
0
votes
1 answer

Use string as bash variable name in alternative value expansion

How can I use the value of one variable as the name of another variable in an alternative value expansion (${var+alt}) in bash? I would think that #!/bin/bash cat='dog' varname='cat' if [ -z ${`echo "${varname}"`+x} ]; then echo 'is…
Chris Middleton
  • 5,654
  • 5
  • 31
  • 68
0
votes
1 answer

SQL Dialect Translation Using PERL

I have a rush job to take an SQL product that works on PostGre and Amazon's RedShift, and port it to work on Oracle. (Note that "work" does not currently imply "optimally" but rather "correctly".) All of our TABLEs are defined using an ORM (DBI),…
MatBailie
  • 83,401
  • 18
  • 103
  • 137
0
votes
2 answers

cmd for loop mass renaming again oneliner

I'm over my head with this - spent too much time searching already - evidently I don't understand the basics of CMD variables etc. - and it always gives me such a headache why wouldn't this work? for %a in (*) do ( set tmpx=%a & echo %tmpx% ) the…
hello_earth
  • 1,442
  • 1
  • 25
  • 39
0
votes
2 answers

Prevent expansion of `~`

I have a script which sync's a few files with a remote host. The commands that I want to issue are of the form rsync -avz ~/.alias user@y:~/.alias My script looks like this: files=(~/.alias ~/.vimrc) for file in "${files[@]}"; do rsync -avz…
pfnuesel
  • 14,093
  • 14
  • 58
  • 71
0
votes
1 answer

bash script to build complex command syntax, print it first then execute - problems with variable expansion

I want to create scipt to faciliate producing local text file extracts from Hive. This is to basically execute commands like below: hive -e "SET hive.cli.print.header=true;SELECT * FROM dropme"|perl -pe…
msciwoj
  • 772
  • 7
  • 23
0
votes
2 answers

bash parameter expansion within a scalar variable via echo

title: bash parameter expansion within a scalar variable I have a bash script which runs a diff between two files. If there is a diff, I want it to print statement1 and statement2 They are long so i put them into variables, but the echo…
capser
  • 2,442
  • 5
  • 42
  • 74
0
votes
1 answer

Using argument expansion {*} with more than one statement

I am using {*} in tcl for argument expansion and come across this issue. #!/usr/bin/tclsh set reset { set count 0; set age 24; } puts $reset eval $reset; # This is working fine. Commented out the below line and tried {*}$reset; #…
Dinesh
  • 16,014
  • 23
  • 80
  • 122
0
votes
1 answer

How to quote bash flag arguments to pass through one getopts call and be interpreted by a second?

Script nerf calls script herd, which calls script er. nerf uses a flag on herd that explicitly takes arguments needing to be passed to er. This was not a problem before nerf existed - when herd was just called from the command line, we could…
0
votes
1 answer

How do I execute a dos command with variable arguments

If I run: -e "SHOW DATABASES" -u -p It runs. But if I try: -e "SHOW DATABASES" -u$sqlUser -p$sqlPassword it fails because the variables are not being expanded. What is the simplest way to accomplish this…
0
votes
1 answer

BASH better way to do a look back?

hey guys I'm wondering if there is a smart way to look back before a period in bash file='foo'/bar/styles.css?ver=1.4.2 ext=$(echo ${file} | gawk -F "?" '{print$1}') echo "${ext##*.}" # css Seems like I should be able to do this all in my…
ehime
  • 8,025
  • 14
  • 51
  • 110
0
votes
1 answer

What does this code do in bash?

I'm trying to modify someones script, and there's a certain part of it that's really confusing to me. It looks like below. if [[ ! -f "${0%/*}/somefile" ]]; then echo "Cannot find somefile, quiting..." >&2 exit 1 else source…
Joshua Strot
  • 2,343
  • 4
  • 26
  • 33
0
votes
1 answer

Use variable expansion in heredoc while piping data to gnuplot

I normally use a code like following to pipe data from a file to gnuplot and create a picture during the Perl script: #!/usr/bin/perl use warnings; use strict; my $in="file.dat"; open(GP, "| gnuplot") or die "$!\n"; print GP << "GNU_EOF"; set…
EverythingRightPlace
  • 1,197
  • 12
  • 33
0
votes
1 answer

python/bash variable expansion in for loop for json array

Here is my problem. I have the following bash snippet: #!/bin/bash R1=$(cat $HRESULTPATH/KEYLIST.OUT|grep "$KEYCHAIN") H1=$(echo $R1|tr -d [[:space:]]) O1=$(echo $H1|tr -d '\"') S1=$(echo $KEYCHAIN|tr -d [[:space:]]) export TESTCASE1=`echo "CLI -…
HM Stanley
  • 145
  • 4
  • 14
0
votes
1 answer

Variable expansion in python using dictionaries

I am facing the following problem; Somewhere inside my script I have defined a function def lookup(type, value): doctors = {'doctor1':"Smith", 'doctor2':"Rogers"} supervisors = {'super1': "Steve", 'super2': "Annie"} print…
stratis
  • 7,750
  • 13
  • 53
  • 94
1 2 3
16
17