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
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
    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 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.