The variable tag has no wiki summary.
2
votes
1answer
34 views
grep misreads pattern from variable
I have a problem with escaped pattern put in grep.
My test file is:
export_cc = ${dir}/aaa/bbb/ccc
export_cc = ${dir}/aaa/bbb/eee
export_cc = ${dir}/aaa/bbb/ddd
export_cc = ${dir}/aaa/bbb/fff
...
0
votes
1answer
27 views
How to grouped the following variable and command and read 1 by 1
I've following array and variable :
httpurl="http://www.nnin.com"
firstquery=$(curl -s -X POST -d "UID=user1&PWD=1111" $httpurl)
name="firstcust"
ip="105.105.0.1"
httpurl="http://www.mmim.com"
...
0
votes
0answers
28 views
Avoiding heredoc sh[process_number].* files in /tmp directory
I have a .ksh file which logs into sqlplus and runs some queries. The block of code is something as mentioned below:
//Other things done in ksh
sqlplus -s @connect.sql << EOF
Query1
Query2
...
3
votes
2answers
111 views
When should one use $( ) in defining variables
Some shell scripts I have come across use the following syntax when defining variables:
file_list_1=$(echo "list.txt")
or
file_list_2=$(find ./)
I would have used:
file_list_1="list.txt"
and
...
0
votes
1answer
47 views
SSH: remote variable
I want to run a complex script via ssh
#!/bin/sh
ARRAY1=(
server1s
server123
server12
server14
server13
)
for i in ${ARRAY1[@]};do ssh $i "
case \$HOSTNAME in
server1.domain.com)
echo try1
...
1
vote
2answers
46 views
Aliasing using for or while loop in .bashrc
Can I use a for or while loop when I have similar pattern in the aliases that I put in my .bashrc file? For example, I have:
alias c0='ssh computer-1-0'
alias c1='ssh computer-1-1'
alias c2='ssh ...
1
vote
2answers
51 views
Identify user defined variables
In a GNU/Linux bash shell, I am using a command to identify and save all my user defined variables at a specific point in time for debugging purposes (I source the file later):
declare | grep ...
-1
votes
0answers
43 views
Replacing string with value of variable using sed or awk
I want to change the value stored in the file by adding one (but without changing other contents) by substituting.
v=`cat FILE |head -n20 \
|grep "Version=" \
|cut -d\= -f2 \
...
2
votes
1answer
10 views
gdb: stop the program when the variable changes
So I was wondering how to stop gdb every time my variable (test_v) changes
I know
watch test_v
Do I do
watch test_v
stop
To stop the program every time the variable test_v changes?
3
votes
1answer
339 views
Linux: set command for local variables
I am trying to understand local/environment variables and export/set commands.
$ set FILEM="razrax"
$ echo $FILEM
$ FILEN="test"
$ echo $FILEN
test
Please explain why echo $FILEM returns empty ...
2
votes
1answer
38 views
When does one need to export a variable? [duplicate]
Eons ago, when I first started assigning variables in bash, it was something along the lines of:
export EDITOR=nano
export PS1=something
...and the likes. And the habit of exporting has kinda stuck ...
2
votes
2answers
46 views
Local variable as a part of global one
I have a question about something similar to this question, but I need to call global variable depending on local one.
Say I want to pass either test, staging, or production as a variable to a ...
3
votes
2answers
82 views
using the variable “file” obtained from `for “file” in` and pass to another script fails [closed]
I am trying search for all .mkv files in my current folder, then using mediainfo I want to put the height from its meta data to a variable, but it seems it is failing.
This snippet:
...
1
vote
2answers
85 views
check if a variable is in list
to check if a word is in a list of words or no I wrote this script:
tr -s '[[:blank:]]' '\n' < t.txt |
while IFS= read -r word; do
if [[ "$word" =~ $(echo ^\($(paste -sd'|' ./champs.txt)\)$) ...
3
votes
3answers
239 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 ...
1
vote
3answers
146 views
Shell expansion for arguments?
For example:
mkdir ~/{1,2,3}
Creates directories ~/1, ~/2, and ~/3. It equates to:
mkdir ~/1
mkdir ~/2
mrdir ~/3
But, using the same syntax in the case of CMD < argument > :
brew {install, ...
-2
votes
3answers
42 views
Syntax error when trying to cut part of a variable
If I write a simple echo $i, I have no problem: it shows me the variable. But if I try do something with it
$($i|cut -d"." -f1-3)
then I get an error messages
: -bash: /...file.backup: Permission ...
2
votes
2answers
140 views
An error of variable type?
I've an error that I don't understand, it seems that that the problem is that my parameters into the shell are not of the same type as what they are in my SQL Database.
For a better understanding: ...
1
vote
1answer
69 views
awk pattern with variable in a bash script
I have problem with command awk in bash
I want to find pattern with variable, but it doesn't work. Can you tell me what's wrong with this line?
awk -F" " "/$PWD/ {print $1,$3}" file.txt
0
votes
3answers
87 views
In BASH is there a way to read Variable names from a variable? [closed]
This is a bash question (hence posting here in Unix&Linux)
I have a while loop that reads from a csv; It looks something like this:
while read NAME PRETTY_NAME DESC; do
echo $NAME
done < ...
4
votes
2answers
128 views
Replace string in a file with another where both are saved in variables
I want to replace a string found in a file with another string, but both have a special character (in this example it is a . char) e.g 1.0 and 2.0.
So this is the command currently used:
sed -i ...
0
votes
0answers
23 views
What mail variable is needed to make sure I receive a copy as well when emailing an alias
The alias includes a list of addresses and includes mine as well what mail variable do I need to make sure I still receive a copy of the message as well?
1
vote
3answers
39 views
Variable related to variable
I want to get effect like bellow but I do not know how:
$> A='/dir'
$> B="$A/bin"
$> echo $B
/dir/bin
$> A='/other'
$> echo $B
/other/bin
any ideas?
4
votes
1answer
154 views
Can I refer to a global variable even if a locally scoped one exists with the same name?
If I have a variable x
total=3
and then a function
function A () {
local -i total=0
}
Is there any way I can update the 'global' total variable total from within function A ?
1
vote
2answers
153 views
How to format decimal number to display the preciding zero but not the trailing ones?
I have the following script on Ubuntu 14.04.1 LTS 64-bit bash command prompt:
S=0.030
F=0.150
N=10
reso=20
DIFF=`echo "scale=3; $F - $S" | bc -l`
df=`echo "scale=3; $DIFF / $N" | bc -l`
is=`echo ...
1
vote
2answers
61 views
scripting- Ignoring a variable when undefined
HP-UX *** B.11.31 U ia64 **** unlimited-user license
Hello,
var1=abc
var2=xyz
touch $var1 $var2 $var3
if the one of the variable is not set the command fails with
ksh: var3: parameter not set
...
1
vote
1answer
23 views
Comparing variables in arithmetic
Was wondering if someone can take the time to explain the following:
I have a directory of files (PDF), which I place into an array.
shopt -s nullglob # Set array ...
0
votes
2answers
51 views
How to use variables properly in this little script?
Here is a little script to retarget old-wrong symlinks that I want to make interactive.
#!/bin/bash
# retarget (broken) symbolink links interactively
echo -n "Enter the source directory where ...
0
votes
1answer
29 views
Is there a valid way of exporting a variable across different shells?
For some reasons, Im using ksh and zsh in my scripts and returning to -bash, I need to use already set variable values in the spawned shells, writing it to some temp file and using that didn't look ...
0
votes
2answers
91 views
In a shell script, How to give a variable another value after one job is done?
I'm trying to make a script which will see if the directory exists and will zip all of its contents under it according to the name/path of the directory.
The farthest I could go was -
...
1
vote
3answers
287 views
sed won't expand my BASH variable in script
I have this script, which will prompt for the relative or absolute path to the file and then swap whitespaces ' ' with '\ ' which works in Linux console. Substitution is done using the first sed ...
0
votes
1answer
491 views
How to assign the cat output of a bash script to a variable in another script
I have a bash script that produces a cat output when it takes an argument. I also have another bash script that executes the first bash script with an an argument that I want to produce cat outputs ...
2
votes
3answers
91 views
Using find with 2 sets of variables
I want to be able to run a find command in my bash script that will find files based on two seperate variables. I've gotten this far but I'm not sure how to get the final result workingfind . -user ...
2
votes
2answers
177 views
Using the output of `grep` as variable in second command
I currently have 2 bash command line strings I use to gather data needed for a certain task. I was trying to simplify and have only one command used to gather the data without using a script.
First I ...
1
vote
1answer
99 views
Read from character delimted file and assign into variables | for email
I am using ksh.
I need to read the data from file, into the variables and then further use them for sending emails.
File can be delimited by any less used characters (like | ^ etc.) or group of ...
3
votes
2answers
137 views
Assign specific line from a variable to another variable
I would like to take a specific line from a variable to another variable.
I tried this but it doesn't work:
c="1.apple
2.banna
3.peach"
read "Please choose fruit [1-3]:" t
a=$c | awk "NR==$t"
echo ...
0
votes
1answer
63 views
Insert variable value as element in array
If I have a variable that has a value stored and I want to place that value into an array using the name of the variable, how would I do this?
e.g.:
variable="Hello there"
array[0]=$variable
does ...
1
vote
3answers
59 views
Use a variable as part of name of an array name?
I essentially have a for loop where the variable i that I am iterating with will take on each letter of the alphabet, for example. I want to use each value of i to create an array called "$i"array ...
1
vote
1answer
64 views
Why doesn't my function work with spaces? (cd, dirname) [duplicate]
I have had this function I use it very often and it works fine.
Here it is:
cdx () { cd `dirname $1` ; }
However, this does not work with spaces. When I use it like this for example
cdx ...
1
vote
1answer
98 views
SQLPLUS value in variable- not working from crontab
I am trying to store sqlplus value to a variable in Linux.
Script is working fine when triggered manually. But value in variable is not stored when the script is called from crontab.
Code:
...
2
votes
1answer
60 views
Export path with space in directory name [duplicate]
I have a path "/third/party/city of las vegas"
when cd the path I use "/third/party/city of las vegas".
In .profile file I have exported the path to a variable as follows
export ...
2
votes
2answers
966 views
How to use variables inside single quotes
I have an application which takes as an input attributes in double quotes embedded in single quotes. Take for example this right command:
command -p 'cluster="cl1"'
In order to automate it, I ...
3
votes
2answers
134 views
How to use tee to capture STDOUT from a code block to a filename defined within the block?
I want to send STDOUT for a script block to a file which name is defined by a variable within the block. However, when I use tee, it seems the variable outside the block doesn't exist anymore. Without ...
-1
votes
1answer
29 views
what directory is used to execute “expr” command,what holds it process-id and log record [closed]
What directory execute the expr command. What directory holds the the PID of the command. What directory hold the log file of this command.and how to read all these??
4
votes
3answers
221 views
Using | pipe character from a $variable makes it treat as just another argument in bash; how to escape it?
I have a bash script like this
export pipedargument="| sort -n"
ls $pipedargument
But it gives the error
ls: |: No such file or directory
ls: sort: No such file or directory
It seems to be ...
4
votes
2answers
293 views
Running commands stored in shell variables
The following works in my shell (zsh):
> FOO='ls'
> $FOO
file1 file2
but the following doesn't:
> FOO='emacs -nw'
> $FOO
zsh: command not found: emacs -nw
even though invoking emacs ...
2
votes
1answer
68 views
Why string comparision results always false
I am trying to do a one time check about apache's mod-status page for updates
like this(this is just a test script):
firstcontent=$(lynx -dump http://some-server/server-status-page)
echo ...
2
votes
4answers
1k views
Extracting the second word from a string variable
I have a string "rtcpOnNbActive true" stored in a variable x. I want to extract "true" as substring and store in a variable. How can I do this?
2
votes
3answers
130 views
How can I print only variables defined inside my shell script?
Lets supose some bash shell script like:
#!/bin/bash
a=3
b=7
set -o posix
set
In this case, the execution of the set variable or some other of the commands to print environment variables ...
0
votes
2answers
103 views
How can I expand all variables at the command line in Zsh?
In an earlier question, specific to bash, I asked How can I expand a relative path at the command line, with tab completion?
I liked @Mikel's answer that mentioned using Ctrl+Alt+e to expand all ...