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


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

Re: I hate shell

From Eli the Bearded <*@eli.users.panix.com>
Newsgroups comp.os.linux.misc
Subject Re: I hate shell
Date 2020-06-23 18:41 +0000
Organization Some absurd concept
Message-ID <eli$2006231427@qaz.wtf> (permalink)
References <rcpqt0$g9i$1@dont-email.me> <qCBywp.rJ1z@yahoo.com> <rcqkss$f17$1@dont-email.me>

Show all headers | View raw


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

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