Nicolas Frbezar Nicolas Frbezar - 5 months ago 6x
Bash Question

Getting error when scripting a command but not when using it manually

Trying to apply this command :

echo $1 | sed -re 's/' | tr '[:lower:]' '[:upper:]'

Manually, it will work (by entering, i will get "SPROD". But when i'm trying to use it in script, i'll get this :

<script_path>: line 34: echo | sed -re 's/' | tr '[:lower:]' '[:upper:]': No such file or directory

What's the problem ?


Here is my usage of the variable :

# uppercase the hostname and cleaning

hostname=$("echo "$1" | sed -re 's/.vdb.local//' | tr '[:lower:]' '[:upper:]'")

# create the command line to add to the command file
cmdline="[$datetime] PROCESS_SERVICE_CHECK_RESULT;$hostname;$2;$3;$4"


Wrong quoting. You have to write it like this:

hostname=$(echo "$1" | sed -re 's/.vdb.local//' | tr '[:lower:]' '[:upper:]')