! error

Hi
I'm trying to finish a script to replace a certain text in a file.
I 'm controlling for the metacharacters, however now there s a problem with "!".
The script is below. The problem I've faced is that if the string i entered is as:

"string! string! string!" 

there aren't any problems. However if the string is as:

"string!string!string!"

i get the followin error:

-bash: !string!string": event not found
 

What can I do to make sure that the script works even if I enter
"string!string!string!"

#!/usr/bin/ksh
$PATH=...
kalacak_1=`grep "RSP_GENERIC_QUERY_123_0_DEFAULT_TURKCE_KONTOR_SUCCESS" $PATH/responses.properties | awk -F* '{print $1}'`
kalacak_2=`grep "RSP_GENERIC_QUERY_123_0_DEFAULT_TURKCE_TL_SUCCESS" $PATH/responses.properties | awk -F* '{print $1}'`
gidecek_1=`grep "RSP_GENERIC_QUERY_123_0_DEFAULT_TURKCE_KONTOR_SUCCESS" $PATH/responses.properties | awk -F* '{print ($NF)}'`
gidecek_2=`grep "RSP_GENERIC_QUERY_123_0_DEFAULT_TURKCE_TL_SUCCESS" $PATH/responses.properties | awk -F* '{print ($NF)}'`
kontrol=`echo $1 | grep '[^ 0-9A-Za-z.,!]' | wc -l`
usage(){
echo "USAGE : ./sample_script.sh "text_to_enter"" 
}
if (( $# == 1 ))
then
karakter_sayisi=`echo $1 | wc -c`
if [ $karakter_sayisi -le 160 ]
then
if [ $kontrol -eq 0 ]
then
cp $PATH/responses.properties $PATH/responses.properties.$(date '+%d%m%y').$(date '+%H%M')
sed -e "s/$gidecek_1/$1/g" $PATH/responses.properties >> $PATH/responses.properties_yeni
mv $PATH/responses.properties_yeni $PATH/responses.properties
else
echo "Girdiginiz cumle metacharacter icermektedir. Sadece harf,sayi ve .,! kullaniniz"
exit
fi
else
echo "160 karakterden kisa bir metin girmelisiniz."
exit
fi
else
usage
exit
fi

From bash's man page:

VAR='string!string!string!'
or
VAR=string\!string\!string\!

I dont have the chance for VAR=string\!string\!string\!
however
VAR='string!string!string!'
worked thankyou..
In . and , I dont have any problems when I use ""
is there any other way to solve this issue so that even if "" is used ! wouldn't be any trouble?

I think you would get more help if you provided more parts of the text you are trying to process and example results of what you are trying to achieve. You have to follow certain rules in programing but there is always a way to get the results you are looking for.

In bash:

$ echo "a!"
-bash: !": event not found
$ set +H
$ echo "a!"
a!

But your script uses ksh, which does not have this feature/problem. So if you experiencing this, then you are probably somehow calling the script using bash instead of ksh...

1 Like