Sponsored Content
Full Discussion: OR'ing condition in script
Top Forums Shell Programming and Scripting OR'ing condition in script Post 69859 by Perderabo on Wednesday 20th of April 2005 10:19:54 PM
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?
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
LN(1P)							     POSIX Programmer's Manual							    LN(1P)

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
ln - link files SYNOPSIS
ln [-fs] source_file target_file ln [-fs] source_file ... target_dir DESCRIPTION
In the first synopsis form, the ln utility shall create a new directory entry (link) at the destination path specified by the target_file operand. If the -s option is specified, a symbolic link shall be created for the file specified by the source_file operand. This first syn- opsis form shall be assumed when the final operand does not name an existing directory; if more than two operands are specified and the final is not an existing directory, an error shall result. In the second synopsis form, the ln utility shall create a new directory entry (link), or if the -s option is specified a symbolic link, for each file specified by a source_file operand, at a destination path in the existing directory named by target_dir. If the last operand specifies an existing file of a type not specified by the System Interfaces volume of IEEE Std 1003.1-2001, the behav- ior is implementation-defined. The corresponding destination path for each source_file shall be the concatenation of the target directory pathname, a slash character, and the last pathname component of the source_file. The second synopsis form shall be assumed when the final operand names an existing direc- tory. For each source_file: 1. If the destination path exists: a. If the -f option is not specified, ln shall write a diagnostic message to standard error, do nothing more with the current source_file, and go on to any remaining source_files. b. Actions shall be performed equivalent to the unlink() function defined in the System Interfaces volume of IEEE Std 1003.1-2001, called using destination as the path argument. If this fails for any reason, ln shall write a diagnostic message to standard error, do nothing more with the current source_file, and go on to any remaining source_files. 2. If the -s option is specified, ln shall create a symbolic link named by the destination path and containing as its pathname source_file. The ln utility shall do nothing more with source_file and shall go on to any remaining files. 3. If source_file is a symbolic link, actions shall be performed equivalent to the link() function using the object that source_file ref- erences as the path1 argument and the destination path as the path2 argument. The ln utility shall do nothing more with source_file and shall go on to any remaining files. 4. Actions shall be performed equivalent to the link() function defined in the System Interfaces volume of IEEE Std 1003.1-2001 using source_file as the path1 argument, and the destination path as the path2 argument. OPTIONS
The ln utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines. The following option shall be supported: -f Force existing destination pathnames to be removed to allow the link. -s Create symbolic links instead of hard links. OPERANDS
The following operands shall be supported: source_file A pathname of a file to be linked. If the -s option is specified, no restrictions on the type of file or on its existence shall be made. If the -s option is not specified, whether a directory can be linked is implementation-defined. target_file The pathname of the new directory entry to be created. target_dir A pathname of an existing directory in which the new directory entries are created. STDIN
Not used. INPUT FILES
None. ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of ln: LANG Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of IEEE Std 1003.1-2001, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES . ASYNCHRONOUS EVENTS
Default. STDOUT
Not used. STDERR
The standard error shall be used only for diagnostic messages. OUTPUT FILES
None. EXTENDED DESCRIPTION
None. EXIT STATUS
The following exit values shall be returned: 0 All the specified files were linked successfully. >0 An error occurred. CONSEQUENCES OF ERRORS
Default. The following sections are informative. APPLICATION USAGE
None. EXAMPLES
None. RATIONALE
Some historic versions of ln (including the one specified by the SVID) unlink the destination file, if it exists, by default. If the mode does not permit writing, these versions prompt for confirmation before attempting the unlink. In these versions the -f option causes ln not to attempt to prompt for confirmation. This allows ln to succeed in creating links when the target file already exists, even if the file itself is not writable (although the directory must be). Early proposals specified this functionality. This volume of IEEE Std 1003.1-2001 does not allow the ln utility to unlink existing destination paths by default for the following rea- sons: * The ln utility has historically been used to provide locking for shell applications, a usage that is incompatible with ln unlinking the destination path by default. There was no corresponding technical advantage to adding this functionality. * This functionality gave ln the ability to destroy the link structure of files, which changes the historical behavior of ln. * This functionality is easily replicated with a combination of rm and ln. * It is not historical practice in many systems; BSD and BSD-derived systems do not support this behavior. Unfortunately, whichever behav- ior is selected can cause scripts written expecting the other behavior to fail. * It is preferable that ln perform in the same manner as the link() function, which does not permit the target to exist already. This volume of IEEE Std 1003.1-2001 retains the -f option to provide support for shell scripts depending on the SVID semantics. It seems likely that shell scripts would not be written to handle prompting by ln and would therefore have specified the -f option. The -f option is an undocumented feature of many historical versions of the ln utility, allowing linking to directories. These versions require modification. Early proposals of this volume of IEEE Std 1003.1-2001 also required a -i option, which behaved like the -i options in cp and mv, prompting for confirmation before unlinking existing files. This was not historical practice for the ln utility and has been omitted. FUTURE DIRECTIONS
None. SEE ALSO
chmod(), find, pax, rm, the System Interfaces volume of IEEE Std 1003.1-2001, link(), unlink() COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 LN(1P)
All times are GMT -4. The time now is 07:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy