OR'ing condition in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting OR'ing condition in script
# 8  
Old 04-20-2005
Quote:
Originally Posted by Just Ice
however, i've never really used the "-f" option --- like most other esoteric options of other commands that are good to know but not required for basic stuff --- so i don't actually understand the unlink statement ... maybe one of the hardcore c programmers here can explain it better ...
Consider this:
Code:
$ date > one
$ touch two
$ chmod 0 two
$ cp one two
cp: cannot open 'two': Permission denied
$ cp -f one two

With the first cp, I could not open "two" for writing (could not obtain a file descriptor). By unlinking "two", the second cp command created a new "two" from scratch. However, the language you quoted implied that cp would first try to open the destination file and if that worked, bypass the unlink. More normal language is:
Quote:
Force existing destination pathnames to be removed before copying, without prompting for confirmation. This option has the effect of destroying and replacing any existing file whose name and directory location conflicts with the name and location of the new file created by the copy operation.
And that could cause a different result. The above language came from HP-UX. What OS supplied your language?
# 9  
Old 04-20-2005
Solaris 8 ...
# 10  
Old 04-21-2005
Oh my...

You're right. Solaris does say that! I just tried the sequence
touch three
ln -s three two
date > one
cp -f one two
on both Solaris and HP-UX. On HP-UX, I get a brand new file called "two" and "three" is untouched. On Solaris, three is overwritten. Smilie

And I just checked the posix standard. According to the standard, Solaris has it right and HP-UX has it wrong.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Condition in bash script

I want get from user and pass these parameters to bash script. script should copy files in user home directory. FYI: each file might be exist or not, might be one of them exist or four of them. Here is my script, it always copy file1 and seems only one of them execute! #!/bin/bash for... (6 Replies)
Discussion started by: indeed_1
6 Replies

2. Shell Programming and Scripting

Creating a condition on a bash script

I wrote a code to find codons in a DNA string. The only problem I have is how do I make the code only work for a file with DNA. This means the file only has the characters a,c,g,t and no white space characters. (3 Replies)
Discussion started by: germany1517
3 Replies

3. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

4. UNIX for Dummies Questions & Answers

While condition in shell script

while do if ;then read driverName else driverName="" fi done can anyone please explain what exactly is happening on 1st line...is it like the conditions being ORed...I have no clue about this. (4 Replies)
Discussion started by: rtagarra
4 Replies

5. Shell Programming and Scripting

Script with variable and condition

Hello newbies question... I just need a script able to launch a command when a condition is matched : #!/bin/ksh SIZ = 'cat /nurp/control.lst|wc -l' if test "$SIZ" -gt 0 then echo 1 else echo 2 fi but I receive errors messages ./t2: SIZ: not found 2 whats wrong ? (5 Replies)
Discussion started by: vdurieu
5 Replies

6. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

7. Shell Programming and Scripting

Script printing else condition

Please help what is wrong in below script. It is printing else also, else echo "DATABASE NOT RUNNING :${i} ================================================= #!/usr/bin/ksh set -A DBS $(cat /etc/oratab | grep ":Y" | awk -F : '{print $1}') set -A RDBS $(ps -ef | grep -i pmon | grep... (3 Replies)
Discussion started by: allwin
3 Replies

8. Shell Programming and Scripting

Condition in script

Hi all, I am writing a script (.sh) which takes backup of database, zip it ftp to remote server and finally mail me to notify. So far this all has been done, however, now I am looking to add notification over each step. Means if any step is failed, then I should get an email and if all goes... (2 Replies)
Discussion started by: viki250
2 Replies

9. Shell Programming and Scripting

grep'ing and sed'ing chunks in bash... need help on speeding up a log parser.

I have a file that is 20 - 80+ MB in size that is a certain type of log file. It logs one of our processes and this process is multi-threaded. Therefore the log file is kind of a mess. Here's an example: The logfile looks like: "DATE TIME - THREAD ID - Details", and a new file is created... (4 Replies)
Discussion started by: elinenbe
4 Replies

10. Shell Programming and Scripting

IF condition failing in a SSH script

Hi, I'm ssh-in to a remote machine (ubuntu) and trying to execute a little script in there.The script looks like this: ssh user@ubuntu <<EOF cd ~/test ls -l echo "Continue counting files starting with a`s ?" read answer if then ls -l a* else exit fi EOF Now everything works... (9 Replies)
Discussion started by: rubionis
9 Replies
Login or Register to Ask a Question