help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] ${var:?message} customization


From: Stephane Chazelas
Subject: Re: [Help-bash] ${var:?message} customization
Date: Thu, 14 May 2015 10:09:34 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

2015-05-13 20:54:09 -0300, Matias A. Fonzo:
> Hi there,
> 
> Normally, "${var:?'message'}" display error if null or unset if
> 'message' is omitted. But if it is not, a particular message can be
> included, in any case, shows (e.g):
> 
>   myscript: line 2: var: parameter null or not set
> 
> My question is, there is a way to print only the message? (removing
> myscript: line number: var:)
[...]

I don't think so, but if stderr is going to a terminal, you
could tell the terminal to erase it:

${var:?$'\r\e[Kblah blah}

In most terminals
\r brings the cursor to the first column
\e[K deletes to the end of the line.

If your message is bigger than the line number prolog, you can
ommit the \e[K part.

In anycase, you can always to it by and:

# for ${var:?blah}
if [ -z "$var" ]; then
  echo >&2 blah
  exit 1
fi
# for ${var?blah}
if [ -z "${var++}" ]; then
  echo >&2 blah
  exit 1
fi

-- 
Stephane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]