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


Groups > comp.os.linux.misc > #30168 > unrolled thread

I hate shell

Started byThe Natural Philosopher <tnp@invalid.invalid>
First post2020-06-22 09:42 +0100
Last post2020-06-23 13:32 +0200
Articles 13 on this page of 33 — 13 participants

Back to article view | Back to comp.os.linux.misc


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#30210

FromJoe Beanfish <joebeanfish@nospam.duh>
Date2020-06-24 20:54 +0000
Message-ID<rd0eht$i3e$1@dont-email.me>
In reply to#30199
On Tue, 23 Jun 2020 16:58:34 +0200, Aragorn wrote:

> On 23.06.2020 at 14:17, Joe Beanfish scribbled:
> 
>> On Tue, 23 Jun 2020 10:15:37 +0200, Aragorn wrote:
>> > 
>> >    for video in *
>> >    do
>> >      name-without-suffix=$(basename ${video%.*})
>> >      # Do your encoding stuff here
>> >    done  
>> 
>> Hyphens aren't valid in variable names. Use underscore or camelCase
>> or something. Add quotes to handle spaces in file names.
> 
> I know that.  It wasn't meant to be taken literally.
> 
>> name_without_suffix=$(basename "${video%.*}")
>> 
>> When someone's struggling with shell syntax, it helps to use
>> syntactically valid examples. Saying "here's my pseudo-code
>> example, go rtfm to fix it" doesn't help.
> 
> He's been around for so long that he ought to have known about these
> things things better than I do.  He wasn't struggling at all.  He's just
> deliberately being obtuse so as to warrant a diatribe against shell
> syntax.

If you feel that way about it, then just skip merrily on to the
next message without replying.

[toc] | [prev] | [next] | [standalone]


#30211

Fromgazelle@shell.xmission.com (Kenny McCormack)
Date2020-06-24 23:24 +0000
Message-ID<rd0nb9$8e0$1@news.xmission.com>
In reply to#30210
In article <rd0eht$i3e$1@dont-email.me>,
Joe Beanfish  <joebeanfish@nospam.duh> wrote:
>On Tue, 23 Jun 2020 16:58:34 +0200, Aragorn wrote:
>
>> On 23.06.2020 at 14:17, Joe Beanfish scribbled:
>> 
>>> On Tue, 23 Jun 2020 10:15:37 +0200, Aragorn wrote:
>>> > 
>>> >    for video in *
>>> >    do
>>> >      name-without-suffix=$(basename ${video%.*})
>>> >      # Do your encoding stuff here
>>> >    done  
>>> 
>>> Hyphens aren't valid in variable names. Use underscore or camelCase
>>> or something. Add quotes to handle spaces in file names.
>> 
>> I know that.  It wasn't meant to be taken literally.
>> 
>>> name_without_suffix=$(basename "${video%.*}")
>>> 
>>> When someone's struggling with shell syntax, it helps to use
>>> syntactically valid examples. Saying "here's my pseudo-code
>>> example, go rtfm to fix it" doesn't help.
>> 
>> He's been around for so long that he ought to have known about these
>> things things better than I do.  He wasn't struggling at all.  He's just
>> deliberately being obtuse so as to warrant a diatribe against shell
>> syntax.
>
>If you feel that way about it, then just skip merrily on to the
>next message without replying.

Back at ya!

-- 
The randomly chosen signature file that would have appeared here is more than 4
lines long.  As such, it violates one or more Usenet RFCs.  In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
	http://user.xmission.com/~gazelle/Sigs/Seriously

[toc] | [prev] | [next] | [standalone]


#30182

FromJack Strangio <jackstrangio@yahoo.com>
Date2020-06-22 23:11 +0000
Message-ID<qCCoCw.16DL8@yahoo.com>
In reply to#30172
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.

[toc] | [prev] | [next] | [standalone]


#30183

FromRich <rich@example.invalid>
Date2020-06-23 01:33 +0000
Message-ID<rcrm4p$6p5$1@dont-email.me>
In reply to#30182
Jack Strangio <jackstrangio@yahoo.com> wrote:
> 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

Give it a try with a path with a directory containing a space and an 
extension with spaces.  I.e., 
something like:

    "/home/test/with space/tail.e x t"

./breakname "/home/test/with space/tail.e x t"

You get this:

FPATH  (dirname)                = /home/test
space
.
.
basename: extra operand 'x'
Try 'basename --help' for more information.
FNAME  (with extension)         = 
FNOEXT (without file extension) = 
FEXT   (file extension alone)   = 
 
Getting filename without an extension using 'basename'
FNOEXT (using 'basename')       = .
 
Reassembling our original CLI filename argument:
/home/test space . ./..

But, if you modify the script in this way:

--- breakname.orig      2020-06-22 21:30:03.012660535 -0400
+++ breakname   2020-06-22 21:32:21.377001069 -0400
@@ -9,19 +9,19 @@
 
 ##################################################
 
-FPATH=$(dirname $FN)
+FPATH=$(dirname "$FN")
 echo "FPATH  (dirname)                = $FPATH"
 
-FNAME=$(basename $FN)
+FNAME=$(basename "$FN")
 echo "FNAME  (with extension)         = $FNAME"
 
-FNOEXT=$(echo $FNAME | sed "s/\..*$//g" ) 
+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")
+FEXT=$(echo "$FNAME" | sed "s/^.*\.//g")
 echo "FEXT   (file extension alone)   = $FEXT"
 
 #Note squiggly brackets purely to define a variable-name more clearly,
@@ -29,11 +29,11 @@
 
 echo " "
 echo "Getting filename without an extension using 'basename'"
-FNOEXT=$(basename $FNAME .${FEXT})
+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 "Reassembling our original CLI filename argument:"
+echo "$FPATH"/"${FNOEXT}"."$FEXT"
 echo " "


You get this:

./breakname "/home/test/with space/tail.e x t"
 
FPATH  (dirname)                = /home/test/with space
FNAME  (with extension)         = tail.e x t
FNOEXT (without file extension) = tail
FEXT   (file extension alone)   = e x t
 
Getting filename without an extension using 'basename'
FNOEXT (using 'basename')       = tail
 
Reassembling our original CLI filename argument:
/home/test/with space/tail.e x t

[toc] | [prev] | [next] | [standalone]


#30186

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2020-06-23 05:07 +0100
Message-ID<rcrv6s$4l8$3@dont-email.me>
In reply to#30183
On 23/06/2020 02:33, Rich wrote:
> Jack Strangio <jackstrangio@yahoo.com> wrote:
>> 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
> 
> Give it a try with a path with a directory containing a space and an
> extension with spaces.  I.e.,
> something like:
> 
>      "/home/test/with space/tail.e x t"
> 
> ./breakname "/home/test/with space/tail.e x t"
> 
> You get this:
> 
> FPATH  (dirname)                = /home/test
> space
> .
> .
> basename: extra operand 'x'
> Try 'basename --help' for more information.
> FNAME  (with extension)         =
> FNOEXT (without file extension) =
> FEXT   (file extension alone)   =
>   
> Getting filename without an extension using 'basename'
> FNOEXT (using 'basename')       = .
>   
> Reassembling our original CLI filename argument:
> /home/test space . ./..
> 
> But, if you modify the script in this way:
> 
> --- breakname.orig      2020-06-22 21:30:03.012660535 -0400
> +++ breakname   2020-06-22 21:32:21.377001069 -0400
> @@ -9,19 +9,19 @@
>   
>   ##################################################
>   
> -FPATH=$(dirname $FN)
> +FPATH=$(dirname "$FN")
>   echo "FPATH  (dirname)                = $FPATH"
>   
> -FNAME=$(basename $FN)
> +FNAME=$(basename "$FN")
>   echo "FNAME  (with extension)         = $FNAME"
>   
> -FNOEXT=$(echo $FNAME | sed "s/\..*$//g" )
> +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")
> +FEXT=$(echo "$FNAME" | sed "s/^.*\.//g")
>   echo "FEXT   (file extension alone)   = $FEXT"
>   
>   #Note squiggly brackets purely to define a variable-name more clearly,
> @@ -29,11 +29,11 @@
>   
>   echo " "
>   echo "Getting filename without an extension using 'basename'"
> -FNOEXT=$(basename $FNAME .${FEXT})
> +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 "Reassembling our original CLI filename argument:"
> +echo "$FPATH"/"${FNOEXT}"."$FEXT"
>   echo " "
> 
> 
> You get this:
> 
> ./breakname "/home/test/with space/tail.e x t"
>   
> FPATH  (dirname)                = /home/test/with space
> FNAME  (with extension)         = tail.e x t
> FNOEXT (without file extension) = tail
> FEXT   (file extension alone)   = e x t
>   
> Getting filename without an extension using 'basename'
> FNOEXT (using 'basename')       = tail
>   
> Reassembling our original CLI filename argument:
> /home/test/with space/tail.e x t
> 
The great thing about my C program apart from being shorter, is it 
handled spaces beautifully. One in C a space is just an 8 bit non zero 
quantity...


-- 
Outside of a dog, a book is a man's best friend. Inside of a dog it's 
too dark to read.

Groucho Marx

[toc] | [prev] | [next] | [standalone]


#30203

FromJack Strangio <jackstrangio@yahoo.com>
Date2020-06-24 03:59 +0000
Message-ID<qCEw3I.1IC49@yahoo.com>
In reply to#30183
Rich <rich@example.invalid> writes:
> Jack Strangio <jackstrangio@yahoo.com> 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."

[toc] | [prev] | [next] | [standalone]


#30185

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2020-06-23 05:05 +0100
Message-ID<rcrv29$4l8$2@dont-email.me>
In reply to#30182
On 23/06/2020 00:11, Jack Strangio wrote:
> 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

WONDERFUL. Its longer than my C program!

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


-- 
Outside of a dog, a book is a man's best friend. Inside of a dog it's 
too dark to read.

Groucho Marx

[toc] | [prev] | [next] | [standalone]


#30202

FromEli the Bearded <*@eli.users.panix.com>
Date2020-06-23 18:41 +0000
Message-ID<eli$2006231427@qaz.wtf>
In reply to#30172
In comp.os.linux.misc, The Natural Philosopher  <tnp@invalid.invalid> wrote:
> I couldn't believe that there wasn't a unix utility to do this..

basename will delete a specified (but not arbitary) suffix from a file.

$ basename '/this /path /is /bonker . s' '. s'
bonker 
$ dirname  '/this /path /is /bonker . s'
/this /path /is 
$

> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> // strip extension from file path
> main(int argc, char **argv)
> 	{
> 	char *path;
> 	int len;
> 	if (argc==1)
> 		exit(0);
> 	path=argv[1];
> 	len=strlen(path);
> 	do
> 		{
> 		if(path[len]=='/') // we havent found a period so no extension
> 			break;
> 		if (path[len]=='.') // we have
> 			{
> 			path[len]=0;
> 			break;
> 			}
> 		}
> 	while (--len);
> 	printf("%s",path);
> 	}

So couple of issues I see here. You never declare return the return 
value from from main(), and you never return a value on proper usage,
just "exit(0)" on invalid usage. The lack of a final newline is okay,
but not to my tastes.

Also apparently dot files are all suffix and no file. That could be
an issue. (Note prompt appears immediately after output due to lack
of newline.)

$ ./noext  '/this /path /is /bonker . s'
/this /path /is /bonker $
$ ./noext  /home/username/.newsrc
$ /home/username/$

That never happens with basename, because basename refuses to believe a
suffix can start a filename:

$ basename /home/username/.newsrc
.newsrc
$ basename /home/username/.newsrc .newsrc
.newsrc
$ basename /home/username/.newsrc.newsrc .newsrc 
.newsrc
$

Elijah
------
if you hate shell, Unix might not be the thing for you

[toc] | [prev] | [next] | [standalone]


#30192

From"Anonymous Remailer (austria)" <mixmaster@remailer.privacy.at>
Date2020-06-23 11:12 +0200
Message-ID<0f1c193f822fcc73af3c86bc374eb607@remailer.privacy.at>
In reply to#30171
The Natural Philosopher <...@invalid.invalid> [TNP]:
TNP> strip the extension from a file path if it has one.

"${filename%.*}" is your friend. Test it with

	for i in *; do echo "${i%.*}"; done



TNP> I couldn't believe that there wasn't a unix utility to do this..

It's just your ignorance speaking...

[toc] | [prev] | [next] | [standalone]


#30180

FromRathbone <please@replytolist.com>
Date2020-06-22 20:22 +0000
Message-ID<slrnrf24ng.44a.please@logancomp.rathbonelaw.com>
In reply to#30168
On 2020-06-22, The Natural Philosopher wrote:
> It simply doesn't behave as the manual says it does.
>
> 6 hours and counting for a 4 line script...sigh. quicker to write in 'C'

Whatever dude, if C works for you for what you're trying to do, just use
it. Why bother spamming the list with this nonsense?

[toc] | [prev] | [next] | [standalone]


#30189

FromAragorn <thorongil@telenet.be>
Date2020-06-23 10:20 +0200
Message-ID<20200623102017.2eea07cb@nx-74205>
In reply to#30180
On 22.06.2020 at 20:22, Rathbone scribbled:

> On 2020-06-22, The Natural Philosopher wrote:
> > It simply doesn't behave as the manual says it does.
> >
> > 6 hours and counting for a 4 line script...sigh. quicker to write
> > in 'C'  
> 
> Whatever dude, if C works for you for what you're trying to do, just
> use it. Why bother spamming the list with this nonsense?

For the same reason as why he's using random right-wing political
quotes as his signature and manages to eventually turn almost every
technical discussion he's involved in into an anti-left-wing
political rant.

I believe it's called "bigotry". <rolling eyes>

-- 
With respect,
= Aragorn =

[toc] | [prev] | [next] | [standalone]


#30191

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2020-06-23 09:41 +0100
Message-ID<rcsf72$c0j$1@dont-email.me>
In reply to#30189
On 23/06/2020 09:20, Aragorn wrote:
> On 22.06.2020 at 20:22, Rathbone scribbled:
> 
>> On 2020-06-22, The Natural Philosopher wrote:
>>> It simply doesn't behave as the manual says it does.
>>>
>>> 6 hours and counting for a 4 line script...sigh. quicker to write
>>> in 'C'
>>
>> Whatever dude, if C works for you for what you're trying to do, just
>> use it. Why bother spamming the list with this nonsense?
> 
> For the same reason as why he's using random right-wing political
> quotes as his signature and manages to eventually turn almost every
> technical discussion he's involved in into an anti-left-wing
> political rant.
> 
> I believe it's called "bigotry". <rolling eyes>
> 
Never confuse bigotry simply with something you and your peer group 
disbelieves for no reason.

Left wing thinking is based on flawed philosophy and extremely flawed 
analysis of human nature and the economics of the kindergarten.


And yet millions of people believe in it because it makes them feel better.


-- 
Climate Change: Socialism wearing a lab coat.

[toc] | [prev] | [next] | [standalone]


#30194

FromAragorn <thorongil@telenet.be>
Date2020-06-23 13:32 +0200
Message-ID<20200623133230.753ea214@nx-74205>
In reply to#30191
On 23.06.2020 at 09:41, The Natural Philosopher scribbled:

> On 23/06/2020 09:20, Aragorn wrote:
> > On 22.06.2020 at 20:22, Rathbone scribbled:
> >   
> >> On 2020-06-22, The Natural Philosopher wrote:  
> >>> It simply doesn't behave as the manual says it does.
> >>>
> >>> 6 hours and counting for a 4 line script...sigh. quicker to write
> >>> in 'C'  
> >>
> >> Whatever dude, if C works for you for what you're trying to do,
> >> just use it. Why bother spamming the list with this nonsense?  
> > 
> > For the same reason as why he's using random right-wing political
> > quotes as his signature and manages to eventually turn almost every
> > technical discussion he's involved in into an anti-left-wing
> > political rant.
> > 
> > I believe it's called "bigotry". <rolling eyes>
> >   
> Never confuse bigotry simply with something you and your peer group 
> disbelieves for no reason.
> 
> Left wing thinking is based on flawed philosophy and extremely flawed 
> analysis of human nature and the economics of the kindergarten.
> 
> 
> And yet millions of people believe in it because it makes them feel
> better.

QED.

-- 
With respect,
= Aragorn =

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.os.linux.misc


csiph-web