Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Jack Strangio Newsgroups: comp.os.linux.misc Subject: Re: I hate shell Date: Wed, 24 Jun 2020 03:59:27 -0000 (UTC) Organization: North Star Horizon Builders Club Lines: 64 Message-ID: References: Injection-Date: Wed, 24 Jun 2020 03:59:27 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="6e81e0bd7eb41798c85cf0b640acf3fb"; logging-data="14128"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1999vJSwFaqOB2M7Hfegneu9teaTL8+/aM=" Cancel-Lock: sha1:5pEOuuu7mG5J6FC5Cl4fPA1zzg0= X-Newsreader: TASS News Reader 3.7.2 jvs [linux] Xref: csiph.com comp.os.linux.misc:30203 Rich writes: > Jack Strangio wrote: > "/home/test/with space/tail.e x t" > > ../breakname "/home/test/with space/tail.e x t" > You mean like this, without basename or dirname: breakname "/home/test/with space/tail.e x t" FNAME (with extension) = "tail.e x t" FPATH (sed) = /home/test/with space FNOEXT (without file extension) = tail FEXT (file extension alone) = e x t Reassembling our original CLI filename argument: /home/test/with space/tail.e x t ================ breakname ======================== #!/bin/bash # # breaks a filename into its path, basename-with-extension, # basename-without-extension, file-extension alone # FN="$@" echo " " ################################################## FNAME=$(echo $FN | sed "s/^.*\///g") echo "FNAME (with extension) = $FNAME" FPATH=$(echo $FN | sed "s/\/$FNAME//g") echo "FPATH (sed) = $FPATH" FNOEXT=$(echo $FNAME | sed "s/\..*$//g" ) echo "FNOEXT (without file extension) = $FNOEXT" #Note the filename and file extension can be extracted either with # or without the '.' separator. Examples below we throw away the '.' FEXT=$(echo $FNAME | sed "s/^.*\.//g") echo "FEXT (file extension alone) = $FEXT" #Note squiggly brackets purely to define a variable-name more clearly, # as in was it '$FNOEXT' or '$FNOEXT.' that was specified? #We reinsert our missing '.' and '/' if need be echo " " echo "Reassembling our original CLI filename argument:" echo $FPATH/${FNOEXT}.$FEXT echo " " ===================================================== Jack -- "Those of you who think you know everything are pissing off those of us who do."