Skip to main content

All Questions

1 vote
1 answer
46 views

How To Use Quotes In Variable In Bash [duplicate]

I need to assign a command to a variable and execute it with variable in linux bash. The command executes fine from command line but not from the variable because of multiple quotes. I hope backslash ...
Kishan's user avatar
  • 113
0 votes
1 answer
40 views

Does Bash have an option to diagnose "expanded to empty value" variables? [duplicate]

Does Bash have an option to diagnose (and optionally abort execution) "expanded to empty value" variables? Example (hypothetical): $ bash -c 'echo $x' --xxx bash: line 1: variable 'x' ...
pmor's user avatar
  • 593
7 votes
1 answer
1k views

printf - store formatted string output in a variable

Instead of the following printf '%s\t%s\t%s\t%s\n' 'index' 'podcast' 'website' 'YouTube' I want to store the printf output in a Results variable, how can I do this?
Porcupine's user avatar
  • 2,146
0 votes
2 answers
172 views

how to replace a string with a variable?

I am trying to write a script containing a loop that enters a series of directories containing the same file, to replace a text string in a file with a variable that matches the directory's name. The ...
Ella Brudner's user avatar
5 votes
2 answers
478 views

Issue expanding variable with multiple wildcards in bash shell script with mv / rename

I wrote a bash shell script for Linux to move files in a static folder according to parameters specified in a data file. I've reduced that script to a minimal reproducible example to demonstrate an ...
Amazon Dies In Darkness's user avatar
0 votes
3 answers
107 views

How to expand variable inside single or double qoutes

I have 2 systems and they have the same directory strcuture. I want to execute a couple of commands on local system and the same on remote system. I use the wildcards so when I have a new version of ...
DEKKER's user avatar
  • 998
0 votes
2 answers
1k views

Export a value from input variable

I need to export the values from input. However it's failing in bash. Here's the code - echo "Please enter HOST :" read RDSHOST && export RDSHOST And my value is something like - ...
Devendra's user avatar
0 votes
0 answers
503 views

how to expand a variable with backslash in bash script [duplicate]

i read a line from another file that contains a backslash, and i want to echo this line without expanding the backslash : script.sh : #!/bin/bash while read line do echo "$line" done &...
hugogogo's user avatar
  • 121
0 votes
1 answer
1k views

Nested variables that rely on one another

I'm trying to automate WireGuard on my OpenWrt router but I'm having some issues with nested variables when it comes to creating my configuration file. Below are the variables I have set: export LAN=&...
willowen100's user avatar
2 votes
2 answers
2k views

sed with external script file - How to apply shell variables?

Directly on the command line, this works: $sed "s/a/X/;s/X/&a&/" file and so does using shell variables: $varin=a ; varout=X ; sed "s/$varin/$varout/;s/$varout/&$varin&/...
FelixJN's user avatar
  • 13.9k
0 votes
1 answer
566 views

Variable in Bash Alias not working as intended [duplicate]

The alias doesn't work properly until running source ~/.bashrc or source ~/.bash_aliases ONLY AFTER running the alias once first. Is there a magical way to get the $todaydir string to be replaced ...
m00tpoint's user avatar
1 vote
1 answer
565 views

Expand shell variable while editing command line

If I write ls bla.* at the prompt and then I press = while the cursor is still on the bla.* part of the command line, the list of files matching bla.* is printed. If I press *, that word is ...
Enlico's user avatar
  • 2,179
0 votes
1 answer
830 views

User input to search bash array

folks-- I'm getting kinda stuck, here. I have a small script that will be incorporated into a larger script. This small piece is supposed to take a user input, and compare it to a list of stored ...
Wayne's user avatar
  • 35
-2 votes
2 answers
4k views

How to execute a command that has many nested single and double quotes with a quoted variable in bash

Here is my simple script #!/bin/sh thefile=/home/ark/arkserver/ShooterGame/Saved/SaveIsland/1288804998.arktribe while inotifywait "${thefile}" ; do a=\"`strings ${thefile} | tail -n 5 | head -n ...
Phorce1's user avatar
  • 19
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

15 30 50 per page