Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

6 votes
4 answers
18k views

Backslash in variable substitution in Bash

I was working on a Bash script to help partition a hard drive correctly, and I came across a strange problem where I had to append a number to a variable. It took me a while to get the outcome right ...
user avatar
3 votes
1 answer
1k views

Double Quotes in Bash's variable substitution

I am trying to configure some software packages with a script thereby I got the following problem. Assume that the environment variable PREFIX is set to the location where I plan to install the ...
M.K. aka Grisu's user avatar
0 votes
2 answers
602 views

Reading output of command into variable in shell, splits text at every white space not just newline

I'm using sh (not bash/csh) on FreeBSD 11, and I don't understand this: In console Command: zpool status -v Result: pool: My_pool state: ONLINE status: One or more devices is currently being ...
Stilez's user avatar
  • 1,271
1 vote
2 answers
2k views

Use sed command with variables

I have tried every possible solution available on the Stack Overflow and its related websites but did not find any solution. I spent a reasonable amount of time on this issue and am finally posting ...
kskp's user avatar
  • 177
5 votes
3 answers
8k views

Spaces for variables in bash script

I have a space in one of the directory names. I want to list a file under it from a bash script. Here is my script: fpath="${HOME}/\"New Folder\"/foobar.txt" echo "fpath=(${fpath})" #fpath="${HOME}/$...
kmad1729's user avatar
  • 153
1 vote
1 answer
2k views

bash adds apostrophes to expanded variable

I am reading in a file inside my bash script where each line consists of multiple columns like this: ANSIBLE 'first run' '--diff --extra-vars "client=yes fast=no"' As you can see, the line consists ...
Thomas Steinbach's user avatar
19 votes
2 answers
95k views

Passing a variable to sed [duplicate]

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt looks ...
user2013619's user avatar