weird thing is happening for -f switch
Hallo Folks,
I am having issue with -f switch for conditional if statement. export TAR_FILENAME=${CCB_ENVNAME}_PRE_${RELEASE}_UPGRADE_`hostname -s`.tar.gz if [[ -f "${TAR_FILENAME}" ]];then echo "Application tar ball exist please check backup directory" exit 1 fi this one doesn't work if file is present it should fail, but it overwrites existing file, any problemo in script? Please assist. Many thanks. |
what is the output?
anyway, have you install perl? |
Try this
Code:
#!/bin/bash @TKH: this is shell, not Perl |
No file name doesnot has a space in it.
I shall try iv option alongwith -x Shall update soon. Cheers |
@TKH
as chirsm01 says it is bash and not perl :) |
@chrism01
in meanwhile can you please xplain me what is the difference and what is correct style? {code} if [[ -f "${TAR_FILENAME}" ]] then echo "Application tar ball exist please check backup directory" exit 1 fi {code} OR {code} if [[ -f "${TAR_FILENAME}" ]];then echo "Application tar ball exist please check backup directory" exit 1 fi {code} What is the correct syntax? |
Technically either is allowed, but I prefer mine as being easier to read, including indenting :)
You might find these useful http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ PS code tags howto https://www.linuxquestions.org/quest...do=bbcode#code for posting on LQ |
My bad I was using confluence standard on forum! :(
Thanks for that. Ran script twice still cannot understand why the heck it is not working :( Code:
echo $TAR_FILENAME |
Would my check condition change for a .tar.gz file.
The manual says if [[ -f file ]] true for a regualr file not sure if that .tar.gz is a regular file? |
Code:
file BLD02CCA_PRE_1.9.0.6.6.12_UPGRADE_tmelbld12.tar.gz |
moving slowly and steadily.
noclobber variable may give me answer:) |
still close
Code:
set -o |
Now I am wondering what role does if [[ -f ] does if we can achieve same by set -o noclobber?
I commented out if loop and just set, set -o noclobber and it works fantatstic. Still not satisfied why -f is not working................ |
Perhaps the file is not a regular file. You could test by
Code:
file "${TAR_FILENAME}" |
@catkin yes the file is not regular file.
It says gzip compressed data how can I test then? |
All times are GMT -5. The time now is 05:50 PM. |