1

I write shell where date and time will be input to it.

if date `+%d-%b-%y` -d $1 >> /dev/null 2>&1; then echo "Date Provided by user : $1" else echo "Wrong date format please refer ReadMe for correct format" echo "You have eneterd : $1" exit 1 fi if date `+%H:%M` -d $2 >> /dev/null 2>&1; then echo "Time Provided by user : $2" else echo "Wrong Time format please refer ReadMe for correct format" echo "You have eneterd : $2" exit 1 fi 

It is working fine as expected but problem is that it prints below in nohup.out

./ntwk_resource_rollback.sh[31]: +%d-%b-%y: not found [No such file or directory] Date Provided by user : 07-feb-17 ./ntwk_resource_rollback.sh[39]: +%H:%M: not found [No such file or directory] Time Provided by user : 03:36 

So i want to remove the error it showing for no directory found from nohup.out as this nohup.out could be read by client for debugging purpose.

I can use KSH or BASH for this script.

Please advise what wrong i am doing here !

6
  • 3
    I suggest to replace all backticks by '. Commented Mar 4, 2017 at 9:38
  • wondering how it could working fine as expected even without nohup. Explantion: see @Cyrus's comment. Commented Mar 4, 2017 at 9:47
  • When i say it is working fine because it gives me error message if i give wrong input but but the thing is it gives me no directory found error which is not good to show on screen or someone might may take it in wrong way Commented Mar 4, 2017 at 9:51
  • @Cyrus: Thanks cyrus it works. But could you please provide me some explanation as what wrong i was doing ! And i want to mark your comment as correct answer Commented Mar 4, 2017 at 10:01
  • 1
    This might help: Differences between doublequotes “ ”, singlequotes ' ' and backticks ´ ´ on commandline? Commented Mar 4, 2017 at 10:08

1 Answer 1

1

When you use backticks, like in +%d-%b-%y, the shell is trying to execute a program called +%d-%b-%y, and then pass it as an argument to date. Of course it fails because there is no such program.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.