Nicolas Frbezar Nicolas Frbezar - 6 months ago 13
Bash Question

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

Trying to apply this command :

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


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

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


What's the problem ?

EDIT



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"

Answer

Wrong quoting. You have to write it like this:

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