The tag has no usage guidance.

learn more… | top users | synonyms

0
votes
0answers
8 views

Issues with storing an echo of a date conversion into a string variable inunix

Apologies but this question comes from a question previously raised: How can I convert a local date-time into UTC date-time? Toby has been absolutely great helping me with some conversion string-->BST ...
0
votes
1answer
38 views

Parsing a file to determine what values to use [duplicate]

I have a script and a "config" file that pull variables from. I created the configuration file called config.cfg and used it in my script as such: #! /bin/bash if [ -f ./config.cfg ] then ...
0
votes
2answers
37 views

Different behaviour of eval “ command \”$@\“ ”, “$@”, and “$(echo $@)” when used as arguments [duplicate]

I would like to pass multiple arguments to the Tor browser (firefox) programatically through a function arbitrarily entitled tor. This is so as to command tor search terms and voila! My search terms. ...
9
votes
3answers
293 views

Define variables with a variable name

What's wrong with this script? I'm trying to define A1=1, B1=1, C1=1 LIST="A B C" for x in $LIST do "$x"1=1 done and the result is: ./x.: line 7: A1=1: command not found ./x.: line 7: B1=1: ...
4
votes
3answers
81 views

How to use call-by-reference on an argument in a bash function

I am trying to pass a "var name" to a function, have the function transform the value the variable with such "var name" contains and then be able to reference the transformed object by its original ...
1
vote
4answers
64 views

bash dynamic (variable) variable names

I want to dynamically create a sequence of strings by manipulate an array of elements and create some arithmetic procedure. for name in FIRST SECOND THIRD FOURTH FIFTH; do $name = $(( $6 + 1 )) ...
0
votes
1answer
57 views

How to use pipe to assign a variable [duplicate]

I am new to bash script. Probably this is very easy but for me it's not working. How can I assign value of $x1+$x2 to bc by piping. here in my code $bc holds no value. echo -n 'value x1 : ' read x1 ...
1
vote
2answers
64 views

Copy Single Value from a file to a variable and perform arithmetic over it? [duplicate]

Suppose we have a file like 'abc.txt' which has a single value 123456 and file 'xyz.txt' which also has a single value like 654321. I want to store these values form the file to some shell variable ...
1
vote
2answers
39 views

A variable in Bash that contains quotation marks and spaces

I'm trying the following in a Bash script: MV_PARAMS='"foo 1" "foo 2"' mv $MV_PARAMS What I want to actually execute is: mv "foo 1" "foo 2" But it doesn't seem to work. trying this: mv ...
-1
votes
1answer
38 views

How can I delay the evaluation of variables (lazy evaluation)?

For example, I create 32768 directories named 0,1,2,...32767. I want to randomly choose one as the path every time I run a command. So I change $PATH to $PATH:/blabla/$RANDOM, but it won't work ...
4
votes
1answer
57 views

“$@” expansion for user defined variables

I'm trying to get a (bourne shell) variable to expand like "$@" so it produces multiple words with some having preserved spaces. I've tried defining the variable in many different ways but still can't ...
0
votes
2answers
40 views

Variable expansion inside parenthesis and quotes

In the script below, I can't seem to make $var1 expand in the second statement. I've tried $var1, ${var1}, echo $var1 and '$var1'. It is inside a few sets of quotes and parenthesis which I guess is ...
1
vote
1answer
35 views

Loop over lines of file, partition file and classify each partition

In the following I've put up my code for iterating over lines of a file in order to collect data within a segment from the file in following fashion: Illustration for understanding procedure: segL ...
3
votes
2answers
32 views

Setting variable with default value behaves differently when preceding a command?

Setting a variable with a fallback default value works...as long as we're using the variable in a subsequent command: $ unset APP_ENV $ echo $APP_ENV $ APP_ENV="${APP_ENV:-production}"; echo ...
3
votes
1answer
42 views

Store specific output to a shell variable

I am looking to store the output of the svn info command, more precisely the revision number into a variable for further processing. I just need the 4 stored. Can anyone help me please? $ svn info ...
3
votes
3answers
115 views

What is the difference of defining a variable with or without quotation marks? [duplicate]

If I define a variable with the quotation mark: TEMP="~/Dropbox" then ls $TEMP would not work, instead echo $TEMP | ls works. And to get the same result, I can also define the variable ...
0
votes
1answer
37 views

increment a value pulled from a file

I have a cron that I am writing that will repeat every hour, and I need a simple way to pass a counter from the last run to the next run. My plan was to add the number to a file at the end, and then ...
2
votes
2answers
98 views

Assign variable identifier in loop and echo its value

I hope this question is not a duplicate because I've been trying various ways to solve this problem but couldn't find any solution. I have a for loop in which I'd like to store a command output into ...
1
vote
0answers
22 views

Moving to FHS 3: How to overwrite GNU Autotools directory variables?

In GNU Autotools, the directory variables $sharedstatedir and $localstatedir expand to $(prefix)/com and $(prefix)/var respectively. However the com and var directories don't exist anymore in FHS 3, ...
3
votes
1answer
71 views

Parameter expansion in variable assigned with a wildcard

I have two files in my current folder (MA502) whose names are - MA502_TAAGGCGA-TCGCAGG_L001_R1_001.at.fastq MA502_TAAGGCGA-TCGCAGG_L001_R2_001.at.fastq I have many such folders - ex MA503, MA504 ...
2
votes
3answers
76 views

Split command and arguments, and put into variable in a bash script

I have a script that repeats the same (very long) grep command many times. I want to make the script more readable by cutting the line length, so I tried to put parts of the command into variables. ...
6
votes
6answers
863 views

How do I check if a variable exists in bash?

I need to check a variable's existence in an if statement. Something to the effect of: if [ -v $somevar ] then echo "Variable somevar exists!" else echo "Variable somevar does not exist!" ...
0
votes
2answers
49 views

Replace spaces by underscores in files: Error in my bash script

I don't understand the error in my bash script. #!/bin/bash newFile="" for file in * do newFile={$file/ /_} # so as to replace spaces with underscores mv {$file} {$newFile} done It ...
0
votes
0answers
22 views

Run a command stored in a variable [duplicate]

I am working on updating some scripts we have used previously ( on RHEL) to work for a new flavor of Linux (ESX). As I am modifying the script, I wanted to add user feedback as well as some other ...
1
vote
2answers
60 views

concatenating file names in a variable

I am attempting concatenate file names to use in a ftp mdelete command. Each file name needs to be separated by a space in order for the mdelete command to work. The $i variable is in a loop and I ...
0
votes
2answers
258 views

Why are there three syntax for setting variables in shell scripts?

root@ubuntu:~# echo ${x=1} 1 root@ubuntu:~# echo ${x:=1} 1 root@ubuntu:~# echo ${x-1} 1 root@ubuntu:~# Why are there three syntax for setting variables in shell scripts? What is the technical ...
3
votes
6answers
338 views

How to keep last exit status after test

Is it possible to keep the last command exit status ($?) unaltered after a test? E.g., I would like to do: command -p sudo ... [ $? -ne 1 ] && exit $? The last exit $? should return the ...
1
vote
1answer
45 views

Insert variable in specific place using sed

Please help me i'm trying to insert variable in a file with sed but has not yet successfully(( I have variable $time and i want insert it in index.html file in specific string(line number 53): the ...
5
votes
3answers
690 views

Assigning exit code to a shell local variable

#!/bin/bash function0() { local t1=$(exit 1) echo $t1 } function0 echo prints empty value. I expected: 1 Why doesn't t1 variable get assigned the exit command's return value - 1?
2
votes
3answers
56 views

reuse the last command output at the given index/line-num

ls displays: entry1 entry2 entry3 How can I reuse the above output (not all of the entries but the entry at a given line, say n) in the next shell command? Something like: vi $(!!)@3 Must ...
2
votes
1answer
75 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
37 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
61 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
124 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
145 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
120 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
71 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 ...
2
votes
1answer
14 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
2k 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
50 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
50 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
84 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
139 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
835 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
173 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
59 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
158 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
117 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
126 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
199 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 ...