0

hi i am passing parameter to my shell script and getting very weird result .Below is this script-:

#!/bin/bash
# set the STRING variable
path=$1
echo password | sudo -S -l
sudo /usr/bin/su - abcd  << EOF
cd $path
#write out current crontab
crontab -l > $2
#echo new cron into cron file
echo $3
#echo $3 >> $2
#install new cron file
#crontab mycron
EOF

Above works fine, it goes on specified path,and create backup file but when it goes to echo $3 gives wrong result (weird long string i can not show here).But it only gives that output if pass parameter as belw

./createNewCron.sh /u/siebel/abcd backing.txt "00 09 * * 1-5"

But when i pass string like below it works fine-:

./createNewCron.sh /u/siebel/abcd backing.txt "echo hello"

Can anyone explain me why? Thanks

1
  • hi who ever voted for close i am asking why my echo command giving wrong result with parameter as "00 09 * * 1-5". why is it not printing that value?? Commented Jul 28, 2017 at 9:08

1 Answer 1

2

the shell expands * thus your script receives all the files in your directory. To display the stars, you need to quote echo

echo "$3"
Sign up to request clarification or add additional context in comments.

1 Comment

@Hervr Le Borgne thanks man i am new to it still need to learn more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.