Re: FWD: About Bash Script
I actually re-wrote it and got it working. Thanks for the suggested reading Mart, i'll definitely look those over. Thanks for all the help!
Re: FWD: About Bash Script
Thanks pk! That's the same thin Greg told me. #!/bin/bash if [! -e b.txt]; then mv a.txt b.txt exit fi #The previous commands checks to see if b.txt is NOT already there, if NOT, it renames a.txt to b.txt #If the script gets here, b.txt EXISTS.. # does_exist is a recursive functionlooking at b.txt(i) ..the first b.txt(some number) it finds NOT existing...it creates set i = 1 does_exist[] if [-e b.txt.$i]; { then i = i +1 does_exist else mv a.txt b.txt.$i exit fi } I'm close but getting an eror near the last linenot really sure why ./test: line 25: syntax error near unexpected token `fi' ./test: line 25: `fi'
Re: FWD: About Bash Script
Thanks Greg for the resource material! I'm making changes now
Re: FWD: About Bash Script
Here's what I have but i'm getting some errors #!/bin/bash if ! (-e b.txt); then mv a.txt b.txt exit fi #The previous commands checks to see if b.txt is NOT already there, if NOT, it renames a.txt to b.txt #If the script gets here, b.txt EXISTS.. # does_exist is a recursive functionlooking at b.txt(i) ..the first b.txt(some number) it finds NOT existing...it creates set i = 1 does_exist() { if (-e b.txt.$1); then i = i +1 does_exist else mv a.txt b.txt.$i exit fi }
Re: FWD: About Bash Script
On 16.02.2010 19:52, Curtis wrote: > Thanks pk! > > That's the same thin Greg told me. > > #!/bin/bash > > > if [! -e b.txt]; if [[ ! -e b.txt ]; then ...; fi or if [[ ! - b.txt ]] then ... fi you only need the semicolon if you omit the newline. > > then > > mv a.txt b.txt > > exit > > fi > > > > #The previous commands checks to see if b.txt is NOT already there, if > NOT, it renames a.txt to b.txt > > > > #If the script gets here, b.txt EXISTS.. > > # does_exist is a recursive functionlooking at b.txt(i) ..the > first b.txt(some number) it finds NOT existing...it creates > > > > set i = 1 set??? see: help set i=1 or declare i=1 see: help declare (in you bash prompt) > > does_exist[] you want to define a function? does_exist() { } > > > > if [-e b.txt.$i]; > { this `{' one is bad here. > > then > > i = i +1 i=$((i + 1)) or i=$((i++)) or let i++ or let i+=1 > > does_exist > > else > > mv a.txt b.txt.$i > exit > fi > } > > > I'm close but getting an eror near the last linenot really sure > why > ./test: line 25: syntax error near unexpected token `fi' > ./test: line 25: `fi' > May i suggest some readings: http://tldp.org/LDP/abs/html/index.html http://bash-hackers.org/wiki/doku.php/start http://mywiki.wooledge.org/BashFAQ http://tiswww.case.edu/php/chet/bash/FAQ I sent you this link in my first reply to you: http://groups.google.com/group/comp.unix.shell/browse_thread/thread/233d175274e246bd/b4deba6bf5fea99a?lnk=raot This thread talks about race conditions, that is what i based my first piece of code for you on. That's why i tried not to use if condition then react - type of stuff. Might not affect you at all. However, we see what you are trying to do, but we don't know what for. I guessed file downloading, greg guessed log rotating. It might be a good idea to provide some more information, because that might lead to different solutions. Again however, as i didn't do that before myself, i tried to write some what hopefully meets your requirements: #!/bin/bash f() { [[ $2 ]] || return 1 set -f set -C local in_file="$1" out_file="$2" local i=0 ext= ( until command exec 3> "$out_file$ext"; do ext=.$((i++)) done exec cat "$in_file" >&3 ) 2>/dev/null || exit 1 } f /tmp/a /tmp/b || echo "error" --- the function takes 2 parameters, the name of the input file and the name of the file which may already exist. read the above link, it explains like all commands used here. Best regards Mart
Re: FWD: About Bash Script
Curtis wrote: > if [! -e b.txt]; Please note that should literally be if [ ! -e b.txt ]; NOT if [! -e b.txt]; Try running the latter and you'll get errors.
Re: FWD: About Bash Script
Curtis wrote: > Here's what I have but i'm getting some errors > > #!/bin/bash > > > if ! (-e b.txt); ITYM if [ ! -e b.txt ]; then ...
Re: bash-4.1: incorrect substitution of extended glob pattern when recalled with !$
On 2/13/10 6:03 PM, Rajeev V. Pillai wrote: > Configuration Information [Automatically generated, do not change]: > Machine: i686 > OS: linux-gnu > Compiler: gcc > Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' > -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' > -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash' > -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -O3 > -fomit-frame-pointer -march=native -mfpmath=sse -m3dnow -mmmx -msse -pipe > uname output: Linux athlon.localdomain 2.6.32.8 #1 PREEMPT Wed Feb 10 > 08:06:34 IST 2010 i686 GNU/Linux > Machine Type: i686-pc-linux-gnu > > Bash Version: 4.1 > Patch Level: 2 > Release Status: release > > Description: > When ``shopt -s extglob'' is set, bash-4.1 does not substitute the > complete extended glob pattern when !$ is used to recall it. Thanks for the report. The history library actually understands very little shell syntax. Readline-6.2 will do a slightly better job. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/