All Questions
18 questions
0
votes
0
answers
51
views
Weird behaviour of string concatenation in Bash [duplicate]
I have a problem with bash and string concatenation.
Let's say that I have 2 variables:
FILENAME=/rust-analyzer-x86_64-unknown-linux-gnu.gz
URL=$(http --headers https://github.com/rust-lang/rust-...
-2
votes
2
answers
810
views
Why does echo in Bash modify the content of a independent variable?
I have the following code (minimal example).
#!/bin/bash
...
2
votes
1
answer
2k
views
bash associative array where values are variables, print each value's variable name
I have the following associative array.
var1="dog"
var2="cat"
var3="moose"
declare -A asar01=(
["one"]="$var1"
["two"]="$var2"
[&...
0
votes
1
answer
953
views
Why echo is printing string variables before additional text that have been merged with it?
I have code in bash for making latex file and in this fragment I want to make a table in a loop:
while IFS= read -r line; do
if [[ "$line" == *"comment"* ]]; then
...
0
votes
2
answers
5k
views
Why do I Get a Blank Output When echoing $variable? [duplicate]
I'm just trying to echo a variable stored in a file. When issuing the echo $variable command I'm getting a black area with no output. I don't understand why.
Content of file1:
name="Jhon"
My output
...
10
votes
8
answers
3k
views
How to list all non-environment variables in bash?
I'd like to echo all non-environment variables (all self-declared variables), in Bash 3.2.52.
This command to print all variables gave me output I can't understand that seems to me to conflict with ...
1
vote
2
answers
615
views
How to assign "-e" to a variable in bash
I'm trying to assign -e to a variable in Bash 4. But the variable remains empty.
For example:
$ var="-e"
$ echo $var
$ var='-e'
$ echo $var
$ var="-t"
$ echo $var
-t
Why does it work with -t, ...
2
votes
2
answers
173
views
Linux Bash: Variable to another variable [duplicate]
i have this:
echo $MSG | sed -e $'s/;/\\\n/g'
I want to put the result of that sed in a new variable called $MSG2
Something like:
$MSG2=echo $MSG|sed -e $'s/;/\\\n/g'
How can i do it?
Thank you!
36
votes
3
answers
39k
views
Using `printf` to print variable containing `%` percent sign results in "bash: printf: `p': invalid format character"
I want to use printf to print a variable. It might be possible that this variable contains a % percent sign.
Minimal example:
$ TEST="contains % percent"
$ echo "${TEST}"
contains % percent
$ printf ...
1
vote
1
answer
521
views
Printf format error for number
After some greping and seding I manage to get a value from a csv cell and assign it to a variable (DBR).
Here come some odd findings
echo $DBR
echo "$DBR",
printf "%f" $DBR
output:
9.1
,.1
: ...
1
vote
1
answer
770
views
Define variable using read from stdin of heredoc
I am trying to store Available and Total Memory into variables in a script file as follows,
read -r Available Total <<EOT
$(free -m | awk '/^Mem/{print $7; print $2;}')
EOT
$ echo $Total
$ ...
0
votes
1
answer
58
views
Why does read from variable give blank new variable? [closed]
I am trying to get a folder name from a stored variable string.
When I ran the following
path="Folder%20Name/Dir/File"
read -d "/" folder < <(echo ${path/\%20/ })
echo "$folder"
I am getting a ...
1
vote
2
answers
2k
views
Add Two Spaces in a variable
I need to add two consecutive spaces to a variable. for e.g
I want to write Feb 5 (with two spaces in-between) in a variable. I am using the following command but I get Feb 5 instead. I am using AIX....
13
votes
4
answers
17k
views
Is it possible to print the content of the content of a variable with shell script? (indirect referencing)
Let's suppose I've declared the following variables:
$ var='$test'
$ test="my string"
If I print their contents I see the following:
$ echo $var
$test
$ echo $test
my string
I'd like to find a way ...
0
votes
1
answer
914
views
problem with echo IP address
I'm trying to create basic script which will be run every minute from cron. Script script.sh is:
#!/bin/bash
DATE=`date +"%Y-%m-%d %H:%M:%S"`
IP=`ifconfig | grep "inet addr" | awk --field-separator ':...