"if exists" Bourne Shell


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers "if exists" Bourne Shell
# 1  
Old 09-16-2008
Question "if exists" Bourne Shell

hi all! new to the forum and i love how nice alot of you are. and i was hoping to get some help. a friend of mine asked me to make him a script for backtrack which is based on slax. it makes a new changes.lzm for the usb system and merges 2 files to update it. now i got that handled but i cant seem to over come the simplest of tasks. you see, my entire scrpit relys of weather or not a file exists and weather its there or not it seems to say it exists... my script is simple for this part
Code:
#!/bin/sh
#this is a script i made to merge two .lzm
#files to keep up to date and to make backtrack easy to use

if [ ! -f /mnt/sdb1/BT3/modules ]; then
    echo "changes.lzm found! mergeing new with old .lzm now..."
else
    echo "changes.lzm not found. building new one now..."
fi

please help im starting to feel like a newbie Smilie
# 2  
Old 09-16-2008
A file can exist, but it can be not readable by the current user, or zero-length, or still being written to. All of which cause problems.

[ -r filename ] tells if the user can read the file AND if it exists
[ -w filename ] user can write the file AND it exists
[ -s filename ] file is bigger than zero length and exists.

The still being written to problem is harder. See if the above doesn't get you where you need to be.
# 3  
Old 09-16-2008
wow i feel stupid. i was trying to see if the file DID exist and according to my code...
Quote:
Code:
if [ ! -f /mnt/sdb1/BT3/modules ]; then

i the program was trying to see if it did NOT exist. oops lol thanks for the help jim Smilie i didnt know about the -s
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Problems with "exit" called from function in bourne script

Hi everyone. #!/sbin/sh EXITING() { umount /FOLDER rm -Rf /FOLDER echo "EXIT" exit 0 } EXITING echo "OK" (8 Replies)
Discussion started by: vacadepollo
8 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

Help on "for" loop in bourne shell

Hello Everyone.... I am trying to print a number sequence in following format using for loop. I am using a bourne shell. I tried following for loop condition but it is bash syntax. for (( i=0; i<=5; i++ )) It is giving syntax error. Kindly help with the syntax of "for"... (7 Replies)
Discussion started by: EmbedUX
7 Replies

5. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

6. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

9. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

10. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question