The tag has no usage guidance.

learn more… | top users | synonyms

0
votes
2answers
35 views

Which location does shell assign normal variable?

As you know, bash shell itself is also process. If I use command export a=c, then shell dynamically allocates variable a into location where environment variables are reside.(This environment section ...
0
votes
0answers
42 views

Bash concating strings don't work [closed]

I have searched everywhere and tried a lot of possible option's found here and on Google but none of them seem to work. I have a script that loads variables from a config file and that works (if i ...
0
votes
2answers
30 views

echoing a variable inside a variable

In my environment, the following variable is set: X=/home so echo $X gives me /home Now I set Y=$X echo $Y gives me $X. If I want to get /home using Y is it possible?
5
votes
2answers
40 views

How to store a path built with wildcards and containing with spaces into a variable

Here's the situation (I'm on a Mac, OS X El Capitan): # This works: $ cd /Applications/Adobe\ Illustrator*/Cool\ Extras.localized/en_US/Templates/; # These do not work: $ ...
0
votes
0answers
9 views

Export variable failed when I was compiling NETCDF

I'm compiling NETCDF on Linux. After configure, make,make install, I have already install NETCDF on /disk3/lly/lib/netcdf-4.1.3. Then, using vim ~/.bashrc,edit: export ...
1
vote
0answers
15 views

How do you pass variables to jsc/javascript?

I have a few javascript things that I am running from the Terminal by passing them to jsc, with <<<. (javascript is an alias to ...
1
vote
2answers
33 views

Running Emacs through the value of the bash variable

How would I add a value to a new variable in bash, so that when I echo the variable Emacs would run?
5
votes
2answers
68 views

In bash script, what's the different between declare and a normal variable?

In bash scripting: we create variable just name it: abc=ok or we can use declare declare abc=ok what's the different ? and why bash make so many ways to create variable?
0
votes
1answer
33 views

Create command line variables with PATH

As I am more of a web guy, i need a little help with this one, so I will explain what I am trying to do before I ask. I am creating batch script that will: GET request from an external server (json ...
0
votes
1answer
20 views

How to set up a pre-defined variable with multiple directory paths to use with the find command

I am looking to have a script delete files that are older than 90 days in certain directories. As in, there are 8 directories that have different paths to them. I can run the find command on one ...
8
votes
4answers
180 views

dirname and basename vs parameter expansion

Is there any objective reason to prefer one form to the other? Performance, reliability, portability? filename=/some/long/path/to/a_file parentdir_v1="${filename%/*}" parentdir_v2="$(dirname ...
1
vote
1answer
45 views

Use sed to retrieve variable from 1 file and place it in another

I need to use sed to retrieve a variable form within a file name. I am updating a previous code: cat /directory/filename1.xml | sed -e "s/XYZABC/${c}/g" > /directory/filename2.xml The value for ${c} ...
15
votes
6answers
561 views

Should variables be quoted when executed?

The general rule in shell scripting is that variables should always be quoted unless there is a compelling reason not to. For more details than you probably want to know, have a look at this great ...
0
votes
1answer
31 views

How do I write a Bash script that will ask users to define a variable?

I am presently modifying this shell script to turn it into a shell script for installing Arch Linux, with custom username(s), password(s), etc. At the moment I am wondering what I need to do in order ...
2
votes
2answers
30 views

Exported variables inside ssh session are empty

I am trying to export a variable inside a ssh session and reference the variable in the next write command. sshpass -p "password" ssh -t -t my-box <<EOF export newUrl="this is a url" sudo ...
2
votes
5answers
40 views

Help on edit a sed statement

I'm writing a script to change on the fly the firefox home page through a text variable: sed -i 's|\("browser.startup.homepage",\) "\(.*\)"|\1 "$ddrs"|' /home/max/.mozilla/firefox/*.default/prefs.js ...
3
votes
4answers
412 views

Sum of all Integers between two numbers

I would like to type in two numbers and get the sum of all integers between those two numbers, inclusive. For example: ./sum1 2 5 should yield sum: 14 because 2+3+4+5 = 14 Here's what I have ...
0
votes
1answer
33 views

Script with variable in path

I'm not entirely sure where to ask or how to formulate this question with correct terminology. I have script here for managing a game (minecraft) server for the user (bukkit). I've cut out some ...
1
vote
1answer
34 views

Assign path to variable which does not exist

In an effort of keeping things DRY, I am trying to assign a path to a variable that may not exist and have the following script which returns: /apps/tmp: No such file or directory #!/bin/bash ...
3
votes
5answers
63 views

Bash - Store Color Codes in Variable

How do I store colored text in a variable and print it with color later? I never see the answer to this question in 100 searches it's all about PS1 prompts, or inline printf's or using data from ls ...
0
votes
1answer
51 views

Where is my .sh script syntax error(s)?

Trying to run a small simple script to pull the java -version information from an AIX system's several java64 folders piped into an output/log file using the system's hostname but can't seem to get it ...
1
vote
1answer
31 views

Relation between shell start up processes and environment of parent process

"How are shell variables related to the environment that a process started by the shell has on start-up?" I read If processes inherit the parent's environment, why do we need export? My current ...
1
vote
1answer
55 views

Inserting variables in a command within a shell script

I'm attempting to write an automated script which will update the IP address for my Raspberry Pi within my /etc/hosts file. I'm able to execute this line just fine, IP=`sudo nmap -sP 10.61.4.0/24 | ...
1
vote
1answer
38 views

Linux bash script input without using “read” [closed]

I need to create a bash script where a single argument is passed by the user (without using the "read" input option) at the terminal command line that creates a directory with that name, or otherwise ...
0
votes
3answers
87 views

Passing Variable from one script to another

How can I pass a variable between scripts? Example: I have two test scripts: -- test2.sh #!/bin/bash echo "this is test2.sh" echo "varname is $varname" echo end -- tes1.sh #!/bin/bash ...
2
votes
2answers
42 views

Run a command stored in a variable to echo into a file

How can I get the stored command to work for the following scenario: CMD='echo "test" >> test.txt' $CMD It will work for other scenarios like: CMD='mkdir test' $CMD
2
votes
2answers
51 views

How to replace values in a string using sed but keep the string intact

How to replace values in a string using sed but keep the string intact? For example echo "01XX1234" I'm looking to replace XX with a hex value and leave the 01 and the 1234 intact. I've tried every ...
0
votes
0answers
17 views

Difference between “$@” and “$*” when passing arguments to bash function [duplicate]

I'm having hard time understanding difference between $@ and $* when passing them to functions. Here is example: function a { echo "-$1-" "-$2-" "-$3-"; } function b { a "$@" } function c ...
-3
votes
1answer
27 views

Output the result of a variable

I have an if statement and I want in one case to add one to a variable v and in the other case to a variable inv. I did the following v=$((v + 1)) and inv=$((inv + 1)) I want to outputs the results of ...
1
vote
2answers
43 views

How to set multiple values to the same variable in UNIX?

I am trying to have a script give me the output of multiple words and variations of the words. I tried putting in the -o for the variable, quoting the words, piping them together. The words for each ...
1
vote
1answer
59 views

Bash variables - Any extract tricks based on the order?

Instead of: var1=foofoo var2=barbar var3=jarjar Is there some trick I can to get the variable based on the order it was set in? var=foo var=bar var=jar echo $var2 bar (I know the var ...
2
votes
3answers
49 views

List variables with prefix where the prefix is stored in another variable

I'm trying to list all the variables with a certain prefix, but that prefix is dynamically determined. For example: prefix=apple_ apple_one=a1 apple_two=a2 If I simply do: echo ${!apple_@} I ...
1
vote
3answers
43 views

Pipes vs variable assignment

In what ways are pipes different from variable assignments? I know you can't use null bytes. What other examples are there? What about for piping in something like the following yes | cat? I notice ...
0
votes
1answer
56 views

grep a variable within an if statement

Maybe I am approaching this the wrong way, so I am open for suggestions. I am trying to avoid adding the output of INSTALLED_LIST to a file. I wish to use it within a variable. Basically, I want to ...
0
votes
3answers
50 views

Ignore certain characters when comparing variables?

For example, If this is my script: if [[ $yesno == "What's going on" ]]; then Then how do I make it Ignore ', ?, , and . for example? So basically Whats going on, What's going on, What's going on? ...
0
votes
2answers
47 views

Choose random string from a few and set it as a variable?

I have a few strings, and I want to set a variable to one of them, randomly. Say the strings are test001, test002, test003 and test004. If I set it like normal I'd obviously do it like this: ...
0
votes
2answers
48 views

Date format for variable

I need to write a variable with "date" function and I need that the format is yyyymmdd (i.e. 20151031). Also I would remove a day (i.e. 20151031 becomes 20151030) I would use bash. Thanks!
1
vote
1answer
158 views

Get the output from expect script in a variable

I have an expect script which provides the IP address: #!/bin/expect -f set nodename [lindex $argv 0] spawn virsh console $nodename expect "Escape character is" send "\n" expect "localhost login: " { ...
0
votes
1answer
44 views

ssh pass multiple values

I want to open some ports i do for i in centos7{3..4};do ssh -T $i "for ir in 53 80 443 3000 3306 5910-5930 5432 8140 8443 10090-10100 20 21;do firewall-cmd --permanent --zone=public ...
4
votes
2answers
114 views

Are there shells that supports typed variables and multidimensional arrays?

Is there a shell that supports distinguishing between variable types? At a minimum, it should distinguish between Strings, Integers, Floats and Doubles. The following commands should be different. ...
1
vote
2answers
202 views

Bash script to fill in a template

I have looked for this elsewhere but not able to find something that matches my requirements. The template below is the one I need to use : dn: uid=$1,ou=home,dc=chan,dc=com objectClass: ...
1
vote
1answer
190 views

How to use long variables name in Makefile?

Today I'm learning make command, and I find it seems can execute any bash command by reading Makefile on current directory. However, I encountered a problem. That when using variables, it seems ...
3
votes
3answers
160 views

How do I assign the output of a command to a variable without running the command in a subshell?

If I have a function like this: TEST() { if [[ "$1" == "hi" ]] then exit 1 fi echo "Some text" } and if I run the function in the current shell with: TEST "hi" ...
1
vote
3answers
78 views

How to pass directory with escaped space to variable?

I have a small test.sh script as follows: #!/bin/bash read -e -p "Enter a Directory: " directory echo $directory Here's what happens when I run it: $ ./test.sh Enter a Directory: ~/A\ Directory/ ...
1
vote
1answer
48 views

bash error on eval containing blank space

I need to triggeer a bash passing parameter with a format [ variable_name="value" ] like this: ./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano' On ...
0
votes
2answers
74 views

Initializing a variable with echo

So, I'm trying to store a part of the name of a file into a variable for other uses. So, if my file was named hello123.txt and I want to store the 123 part. So I try num= echo $file |cut -c6-8 ...
1
vote
2answers
175 views

How to count how many ip in bash?

Does anybody know how to count how many ip in bash? For example: Command: root@ubuntu:~$ dig www.google.com A +short | grep -oE ...
0
votes
0answers
24 views

How to reference a variable by its string “name”? [duplicate]

Say for example... #!/bin/bash a1=one a2=two a3=three for x in {1..3}; { echo -n "\$a$x "; } Actual.. $a1 $a2 $a3 Expected.. one two three How can one echo, reference, call, or what ...
1
vote
1answer
233 views

Set variable inside heredoc, use variable outside heredoc

I've got the following in a bash script ssh -T -i ${ssh_key} ${ssh_user}@${host} <<- 'EOF' file=`hostname`.tar.gz echo "file: " $file ### prints>> file: some-host-name.tar.gz EOF ...
0
votes
2answers
38 views

variable inside a variable in a loop

I have a question regarding how a variable can be called with another variable name inside a loop. The following script does not work. #!/bin/bash # Comparing test1.txt with test2.txt, test1.ini with ...