Questions tagged [variable]

A variable is a name, if correctly chosen with a symbolic meaning, that holds a value or values. Use this tag if your question is specific on the use of variables on shell scripting (if you want to ask about variables in programming languages you should probably ask on StackOverflow)

Entry on wikipedia on variables.

1210 questions
91
votes
10 answers

How to assign a string value to a variable over multiple lines while indented?

The issue: I need to assign a variable a value that is decently long. All the lines of my script must be under a certain number of columns. So, I am trying to assign it using more than one line. It's simple to do without indents: VAR="This…
JamesL
  • 1,270
  • 1
  • 14
  • 19
3
votes
2 answers

about dollar sign: dollar sign within dollar sign?

Suppose we have: echo $A abc echo $B def echo $abcdef yesyes How do I get "yesyes" using A and B? I was trying something like: ${$A$B} $`echo "$A"$B` but failed. Any advise?
1
vote
1 answer

Is there a variable-value clone function in Bash and if not, why not?

In PHP, one can copy the variable-value of one variable to another via, for example: $copy = clone $original; This is not the place to ask questions about PHP but I misunderstand why adding the word clone there helps, i.e., why not writing only…
1
vote
1 answer

Declaring a variable that does not have input

I would like to be able to retrieve input from my shell history in order to set variables inside my script. I would then like to use these variables in an if loop, but I am unable to get the variable set correctly. Input stage: My initial input…
1
vote
1 answer

How to print all non-environment variables?

How to print all non-environment variables? These are all the variables I've added myself since the moment the shell started, like when doing: read abc 123 # echo ${abc} => 123 Or xyz='123' # echo ${xyz} => 123 I want to print all of them, to…
0
votes
1 answer

Length variable in netcdf file

I am trying to know the length of a variable 'i' in a netcdf file '122009.nc'. This is my script so far: #!bin/bash var=ncdump -v i 122009.nc var_length=${#var}
Jellyse
  • 223
0
votes
3 answers

Extract the first 2 directories in a path

I need to extract the first 2 directories in a path that is in the variable $ORACLE_HOME ORACLE_HOME=/oradba/app/oracle/product/11.2.0.4/testdb I need the value: /oradba/app/
-2
votes
1 answer

Reading values from variables

I am trying to read values from variables like this server=$(cat "$CONF_PATH" | grep "DevServer" | cut -d'=' -f2) echo "server is : $server " port=$(cat "$CONF_PATH" | grep "DevPort" | cut -d'=' -f2) echo "port is : $port " dbname=$(cat "$CONF_PATH"…
user86683
  • 371
-3
votes
2 answers

Value of the $# variable

set 10 20 30 40 50 Enter the value of the variable $#: I understand that the variables $1=10 $2=20 and so on