2

When I am setting a variable to a command, I am getting the answer along with the error "command not found". Below is the command in the script.

#!/bin/bash

fs=$(ps -C "daemon_name" > /dev/null && echo "Running" || echo "Not Running")

$fs

Output:

./test.sh: Line 5: Running: command not found

1 Answer 1

5

ps is finding the process you are looking for which causes your fs variable to be set to Running. When you call $fs you are essentially just trying to run Running. Since there is no command named Running on your system you get command not found. I imagine you want to echo or printf the result?

printf '%s\n' "$fs"
1
  • 1
    Thank you, your suggestion cleared that up for me. I went with echo, but I tried both and they worked. Have a good one!
    – SLS
    Jun 5, 2019 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .