Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #30182

Re: I hate shell

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From Jack Strangio <jackstrangio@yahoo.com>
Newsgroups comp.os.linux.misc
Subject Re: I hate shell
Date Mon, 22 Jun 2020 23:11:10 -0000 (UTC)
Organization North Star Horizon Builders Club
Lines 76
Message-ID <qCCoCw.16DL8@yahoo.com> (permalink)
References <rcqkss$f17$1@dont-email.me>
Injection-Date Mon, 22 Jun 2020 23:11:10 -0000 (UTC)
Injection-Info reader02.eternal-september.org; posting-host="9b128cbea80faa10c1713a53092ab73b"; logging-data="5523"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19SD8lIrPokkaVmHwhlbWdSm8iEgwkOV+I="
Cancel-Lock sha1:Gzgu+DPUu9molq2QRlKX23mAv5U=
X-Newsreader TASS News Reader 3.7.2 jvs [linux]
Xref csiph.com comp.os.linux.misc:30182

Show key headers only | View raw


The Natural Philosopher <tnp@invalid.invalid> writes:
> 
> I wrote a small bit in C - its strips the extension from a file path if 
> it has one.
> 
> I couldn't believe that there wasn't a unix utility to do this..
> 

Just as a follow-on from this, here's a quick n dirty bit of script

---------------------------------------------------- breakname -------

#!/bin/bash
#
# breaks a filename into its path, basename-with-extension,
# basename-without-extension, file-extension alone
#

FN="$1"
echo " "

##################################################

FPATH=$(dirname $FN)
echo "FPATH  (dirname)                = $FPATH"

FNAME=$(basename $FN)
echo "FNAME  (with extension)         = $FNAME"

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?
 
echo " "
echo "Getting filename without an extension using 'basename'"
FNOEXT=$(basename $FNAME .${FEXT})
echo "FNOEXT (using 'basename')       = $FNOEXT"

#We reinsert our missing '.' and '/' if need be
echo " "
 echo "Reassembling our original CLI filename argument:"
echo $FPATH/${FNOEXT}.$FEXT
echo " "

------------------------------------------------------------------------

In use:

    breakname /home/fred/tmp/murgatroyd.jones
 

FPATH  (dirname)                = /home/fred/tmp
FNAME  (with extension)         = murgatroyd.jones
FNOEXT (without file extension) = murgatroyd
FEXT   (file extension alone)   = jones
 
Getting filename without an extension using 'basename'
FNOEXT (using 'basename')       = murgatroyd
 
Reassembling our original CLI filename argument:
/home/fred/tmp/murgatroyd.jones
 


Jack
-- 
"It's rather cold." she said bitchily.

Back to comp.os.linux.misc | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-22 09:42 +0100
  Re: I hate shell Jack Strangio  <jackstrangio@yahoo.com> - 2020-06-22 14:01 +0000
    Re: I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-22 17:05 +0100
      Re: I hate shell Grant Taylor <gtaylor@tnetconsulting.net> - 2020-06-22 10:23 -0600
        Re: I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-22 18:48 +0100
      Re: I hate shell Robert Heller <heller@deepsoft.com> - 2020-06-22 11:32 -0500
      Re: I hate shell Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-06-22 12:41 -0400
        Re: I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-22 18:49 +0100
      Re: I hate shell Jack Strangio  <jackstrangio@yahoo.com> - 2020-06-22 21:50 +0000
        Re: I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-23 05:04 +0100
          Re: I hate shell Aragorn <thorongil@telenet.be> - 2020-06-23 10:15 +0200
            Re: I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-23 09:38 +0100
              Re: I hate shell Aragorn <thorongil@telenet.be> - 2020-06-23 13:31 +0200
                Re: I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-23 14:09 +0100
                Re: I hate shell Aragorn <thorongil@telenet.be> - 2020-06-23 15:58 +0200
                Re: I hate shell Harold Stevens <wookie@fossa.localdomain> - 2020-06-23 09:16 -0500
            Re: I hate shell Joe Beanfish <joebeanfish@nospam.duh> - 2020-06-23 14:17 +0000
              Re: I hate shell Aragorn <thorongil@telenet.be> - 2020-06-23 16:58 +0200
                Re: I hate shell Rich <rich@example.invalid> - 2020-06-23 16:47 +0000
                Re: I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-23 19:13 +0100
                Re: I hate shell Joe Beanfish <joebeanfish@nospam.duh> - 2020-06-24 20:54 +0000
                Re: I hate shell gazelle@shell.xmission.com (Kenny McCormack) - 2020-06-24 23:24 +0000
      Re: I hate shell Jack Strangio  <jackstrangio@yahoo.com> - 2020-06-22 23:11 +0000
        Re: I hate shell Rich <rich@example.invalid> - 2020-06-23 01:33 +0000
          Re: I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-23 05:07 +0100
          Re: I hate shell Jack Strangio  <jackstrangio@yahoo.com> - 2020-06-24 03:59 +0000
        Re: I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-23 05:05 +0100
      Re: I hate shell Eli the Bearded <*@eli.users.panix.com> - 2020-06-23 18:41 +0000
    Re: I hate shell "Anonymous Remailer (austria)" <mixmaster@remailer.privacy.at> - 2020-06-23 11:12 +0200
  Re: I hate shell Rathbone <please@replytolist.com> - 2020-06-22 20:22 +0000
    Re: I hate shell Aragorn <thorongil@telenet.be> - 2020-06-23 10:20 +0200
      Re: I hate shell The Natural Philosopher <tnp@invalid.invalid> - 2020-06-23 09:41 +0100
        Re: I hate shell Aragorn <thorongil@telenet.be> - 2020-06-23 13:32 +0200

csiph-web