Suppressing errors messages that might occur when using cat command with EOF or EOD in bash script -


my aim suppress error messages might occur when using cat eof or eod.

when run bash script, i'm getting error below because deliberately added / sign @ end of file name.

error

my-hello.sh: line 5: hello.txt/: directory bad 

script

#!/bin/bash  function create() {     cat << eof > hello.txt/     hello eof }  createhook if [ $? -eq 0 ];    printf "good" else    printf "bad" fi 

how can suppress error message being printed on terminal?

i tried 2>/dev/null on eof doesn't because of known white spacing reasons.

note: content of file bigger i've put hello in simplify. i'm open changes if solves problem.

you need use redirection /dev/null this:

function create() {      cat 2>/dev/null << eof > hello.txt/     hello eof } 

you can redirect errors create() function:

function create() {     cat << eof > hello.txt/     hello eof }  createhook 2>/dev/null 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -