shell 调试 2例
?
1.#############
#!/bin/ksh
? if [ ! -z $TNS_ADMIN ]; then
????? export TNS_ADMIN=`dirname $TNS_ADMIN`
??????? else
??????????? export TNS_ADMIN=$ORACLE_HOME/network/admin
????????????? fi
??????????????? echo $TNS_ADMIN
?
調試過程:
? if [ ! -z $TNS_ADMIN ]; then
修改為
if [ ! -z “$TNS_ADMIN” ]; then
?
ref doc https://www.computing.net/answers/programming/error-test-argument-expected/18951.html
Hi,
When i execute the following script i'm getting test: argument expected error at if [ -z $file ]. Can someone plz advise.
if [ -z $file ]
then
echo " DID NOT ENTER A FILE NAME "
elif [ ! -f $file ]
then
echo " \t File ' $file ' Doesn't Exists In $PWD Directory \n"
else
echo " \t File ' $file ' Exists In $PWD Direcotry \n"
fi
Thanks.
?
Report ??
Your script worked for me with no problems:
#!/bin/kshread file if [ -z "$file" ] thenecho " DID NOT ENTER A FILE NAME " elif [ ! -f "$file" ] thenecho " \t File ' $file ' Doesn't Exists In $PWD Directory \n" elseecho " \t File ' $file ' Exists In $PWD Direcotry \n" fiBTW, it's always a good idea to include the shell invocation on line 1 of your script. I'd surround $file with double quotes "$file"Have you tried the extended test facility - two brackets instead of 1:#!/bin/kshread file if [[ -z $file ]] thenecho " DID NOT ENTER A FILE NAME " elif [[ ! -f $file ]] then2.#############
#!/bin/ksh
set -x
export ORACLE_BASE=/opt/oracle11g
export HOME=/home/oracle
export ORACLE_HOME=/opt/oracle11g/product/11.1.0
env
? LSNRLOG=`/opt/oracle11g/product/11.1.0/bin/lsnrctl <<EOF
??? set current_listener yesinuat
????? show trc_directory
??????? EOF`
??????????? ?
??? echo "Listener Log File: $LSNRLOG"
? LSNRLOG=`/opt/oracle11g/product/11.1.0/bin/lsnrctl <<EOF | grep trc_directory | awk '{print $6"/"$1".log"}'
? set current_listener yesinuat
? show trc_directory
? EOF`
????? echo "Listener Log File: $LSNRLOG"
調試過程:
crontab 在調用過程中,只有如下環境變量
PATH=/usr/bin:/usr/sbin:.
LOGNAME=oracle
SHELL=/usr/bin/sh
HOME=/home/oracle
PWD=/home/oracle
TZ=EAT-8
所以需要在你的shell腳本開始加上
##################
. /etc/profile export ORACLE_BASE=/opt/oracle11g
export HOME=/home/oracle
export ORACLE_HOME=/opt/oracle11g/product/11.1.0 ##################
3。######################
man test
轉載于:https://www.cnblogs.com/feiyun8616/p/6548713.html
總結
以上是生活随笔為你收集整理的shell 调试 2例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在Windows 64位下为PHP5.6
- 下一篇: 【PHP】Sublime下PHP网站开发