Skip to main content

All Questions

Tagged with
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-...
hc0re's user avatar
  • 111
-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 ...
kaiya's user avatar
  • 222
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" [&...
Dave's user avatar
  • 700
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 ...
Karolina Pomian's user avatar
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 ...
user10128952's user avatar
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 ...
user avatar
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, ...
Dude's user avatar
  • 83
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!
Kyle Smith's user avatar
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 ...
finefoot's user avatar
  • 3,504
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 : ...
pkaramol's user avatar
  • 3,069
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 $ ...
Porcupine's user avatar
  • 2,146
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 ...
Bret Joseph's user avatar
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....
Hamas Rizwan's user avatar
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 ...
Rafael Muynarsk's user avatar
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 ':...
Rafal Iwaniak's user avatar

15 30 50 per page