New answers tagged variable
3
votes
Accepted
bash: string variable contains asterisk. how to use this variable for searching etc with grep, sed?
For grep, you can use -F to use fixed strings instead of regexes. For sed, it's much more complex. I'd probably switch to Perl which can help you with its \Q/quotemeta function.
#!/bin/bash
s="...
1
vote
Accepted
Bash script variable syntax: with some commands it works, with others it does not
Don't put quotes around tilde ~ if you expect the shell to expand it to your home, so:
SSH_CONFIG_FILE=~/.ssh/config
if you have space(s); do
var=~/'foo bar/file'
With the quotes on tilde, you ...
2
votes
sed: update 2 similar variables in a file but keep the upper and lowercase
As a rule, you should not embed data in the code arguments of language interpreters whether they're shells, sed, awk, perl, python, etc.
Doing so invariably introduces command injection ...
0
votes
Accepted
sed: update 2 similar variables in a file but keep the upper and lowercase
Use grouping \(...\) and referencing (\1 for the first group, \2 for the second etc.):
sed -i "s/\(sid=\).*/\1${CName^^}/gI" dbca2.rsp
For turning the user input to uppercase, the shell is ...
0
votes
Use SED to replace part of a current variable with user input variable
To set the new name dynamically, by a variable, for instance (here only shown for the permanent change):
Close to your attempt:
sed -i "s/gdbName=*.MY.DOMAIN.COM/gdbName=$CDBName/" somefile....
0
votes
Accepted
Use SED to replace part of a current variable with user input variable
Assuming you want to modify a file wherein you have some line,
gdbName=Test.MY.DOMAIN.COM
Then this could be done using
sed "s/^\(gdbName\)=Test\./\1=$CDBName./" somefile
or, if you need ...
Top 50 recent answers are included
Related Tags
variable × 1196bash × 620
shell-script × 332
shell × 246
scripting × 80
awk × 71
sed × 67
linux × 65
quoting × 63
variable-substitution × 49
string × 41
function × 40
array × 39
zsh × 38
environment-variables × 38
echo × 38
text-processing × 36
grep × 35
test × 26
for × 25
read × 24
command-line × 23
find × 22
pipe × 21
ksh × 21