Skip to main content

All Questions

Tagged with
-1 votes
1 answer
451 views

How to store a command output as a variable while erroring out if it fails?

I am trying to do an if statement based on a variable that is command, for instance: ssh_location=$(which ssh) My problem is that, I want to store this only if it exists on the system so I can do ...
Broomey28's user avatar
0 votes
0 answers
115 views

How to put an $ variable inside the printing of a command variable? [duplicate]

Source part: if [ $(jq -r '.patch_at' update.json) -ge "4" ]; then recentlycheckedat=$(echo '('`date +"%s.%N"` ' * 1000000)/1' | bc) contents="$(jq '....
Daniella Mesquita's user avatar
0 votes
2 answers
3k views

How can i store commands as a variables and execute them randomly in bash?

How can i store commands as a variables and execute them randomly in bash? command1=" convert -size 2000x1000 xc:none -gravity center \ -stroke yellow -pointsize 50 -font Courier-BoldOblique -...
Madhubala's user avatar
  • 304
0 votes
2 answers
2k views

Remove unwanted character from a variable

I've seen a few of these questions, and a few answers, but they only tells me how to echo the results to the screen, and often only refers to one character. I need to remove the chars ', and keep ...
JoBe's user avatar
  • 417
-1 votes
1 answer
72 views

Bash: I have a variable in bash script; [duplicate]

I have a variable in bash script dirs= "4"; I want to get this number from another file so I am using a command dirs= sed -n '1p' < test.txt; It gets me the number, I see it in the terminal. But ...
Green's user avatar
  • 15
0 votes
0 answers
25 views

Add locale in variable for command [duplicate]

I'm trying to call a command from a variable in a script with a specific locale, example : $ myYTDL="LANG=C.UTF-8 youtube-dl --get-filename" but each time I try and call it in the script, I get : $ $...
SebMa's user avatar
  • 2,401
0 votes
1 answer
241 views

bash variable does not keep command result

Problem: Storage of the command result in variable portcheck does not work as expected. My script contains this method #!/bin/bash ... status() { portcheck=$(nc -z -v -w5 localhost 8443) ...
Mayoares's user avatar
  • 103
1 vote
1 answer
245 views

Bash - Catch input for a substituted command stored in variable

How would I be able to catch the input for a substituted command stored in a variable? Example: How would I be able to catch the input for the following command? bar_foo=$(openssl passwd -1 -salt &...
Markus Rexhepi-Lindberg's user avatar
2 votes
1 answer
2k views

Run a command stored in a variable to echo into a file

How can I get the stored command to work for the following scenario: CMD='echo "test" >> test.txt' $CMD It will work for other scenarios like: CMD='mkdir test' $CMD
Shayne Manning's user avatar
1 vote
1 answer
2k views

Get two values from command output in a bash script

I have a bashscript, which executes a command and calculates a pair of values, which output can look like this. a,b (10.0000000000, 10.0000000000) -> volt (2088133.7088034691, -222653.3238934391) ...
Matty's user avatar
  • 67