Bunu yapmak istiyorsanız, en büyük amacınızı Bash'te en doğal şekilde yerine getiremeyeceğinizi tahmin ediyorum. Böyle bir şey daha iyi olmalı:
if [ -z $arg ]; then
echo error message >&2;
else
$arg
fi
Bununla birlikte, soruyu daha doğrudan yanıtlama:
(${arg?error message}) |& sed "s/.*: .*: //"
Explanation: The |&
connects the standard error of the block of code in the parentheses (which are necessary for this to work, by the way) into sed
(stream editor), which strips off the part of the message you don't want with a regular expression.