All Questions
84 questions
-1
votes
2
answers
67
views
set output into variable from grep from input variable
whats wrong with this bash script:
acme2=$(dig txt @$1 _acme-challenge.$1.de)
acme3=$(echo $acme2 | grep "^_acme") ...
5
votes
4
answers
520
views
Getting multiple variables from the output of docker exec command in a bash script?
I would like to execute a script on a host machine (script_on_host.sh), which then reaches inside a docker container in order to grab some data using a second script (script_in_container.sh). The data ...
1
vote
2
answers
212
views
Redirect to a filename that will be a variable and contain a command substitution
I'm using nmap to scan a network and then create an XML file that contains the scanned information. I want that XML file to contain the date of the scan so that each file is unique and I can see the ...
1
vote
1
answer
334
views
Change hostname with a variable with for loop
I am trying to change the "hostname --transient" to some computers with a for loop using a variable. I want it to collect the "hostname -f" from the server itself and, using the ...
0
votes
1
answer
706
views
Shell scripting, reading a list from tt file, use as variable, use the variable to run python scripts in a foor loop
I am trying to run a shell script where it reads the variables from a txt file, uses that variable in a for loop to run python file.
The code reads a txt file where at least there are 100 variable ...
0
votes
2
answers
247
views
How to get the Path difference and store it in a variable
Suppose I have two paths. Path1 which is static and path2 which is dynamic.
Example:
Path1= /tmp/folder/
Path2= /tmp/folder/dir1/dir1_2
Result:
Diff= /dir/dir1_2
I want to achieve as above example....
-3
votes
1
answer
60
views
Command prompt write a command
its asks me to
Store the output of the command “hostname” in a variable. Display “This script is running on _.” where “_” is the output of the “hostname” command.
how can I do that
7
votes
3
answers
866
views
Remove repeating string pattern from variable with POSIX parameter expansion
I wanted to use 2.6.2 Parameter Expansion to remove leading characters from a string, but was surprised to find out that "Remove Largest Prefix Pattern" doesn't automatically repeat the ...
9
votes
2
answers
793
views
In POSIX scripting, is x=$y always equivalent to x="$y"?
Are
x=$y
and
x="$y"
always equivalent? Didn't know how to search for this. So far, I've always been using x="$y" to be "on the safe side". But I used x=$1 at one point ...
0
votes
1
answer
670
views
Assigning $* in shell script from args array
After iterating thru the shell arguments and filtering out unwanted arguments into an array, I want to assign the array back to $*.
For example, in the below script, I want to remove the arguments -f ...
1
vote
0
answers
259
views
How to run input (x|grep y) in command [duplicate]
lets say when I execute command and then grep it for a specific output.
for example: man cat|grep "Written"
This gives the name of the authors.
My problem is I want to do this via read.
here ...
0
votes
1
answer
1k
views
How to verify if variable is present when using set -Euo pipefail? [duplicate]
I use following code to verify if variable is not empty and this works fine
VAR=(var1 var2 var3)
chec_var() {
for item in "${@}"; do
if [ -z "${!item}" ]; then
returncode=1
...
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&/...
1
vote
2
answers
3k
views
Using test and date to compare current hour ro range
I am new to Gnu/Linux and bash, and I am trying, unsuccessfully, to write a simple bash script to test if date +%H is within a predefined range of hours.
Example:
hour='date +%H'
if [[ $hour -ge 12 ]] ...
1
vote
4
answers
123
views
String substitution to detect empty variables?
I have a script that iterates through files and does some string substitution to insert the date.
#!/bin/bash
f="/tmp/file.txt" # with .txt extension
timestamp="$(date +%H%M%S)"
...