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


Groups > linux.debian.user > #172814 > unrolled thread

Re: Substring search in dash [ _NOT_ bash ] shell

Started byGreg Wooledge <wooledg@eeg.ccf.org>
First post2016-09-26 17:50 +0200
Last post2016-09-27 10:00 +0200
Articles 4 — 4 participants

Back to article view | Back to linux.debian.user

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Substring search in dash [ _NOT_ bash ] shell Greg Wooledge <wooledg@eeg.ccf.org> - 2016-09-26 17:50 +0200
    Re: Substring search in dash [ _NOT_ bash ] shell Richard Owlett <rowlett@cloud85.net> - 2016-09-27 06:00 +0200
      Re: Substring search in dash [ _NOT_ bash ] shell The Wanderer <wanderer@fastmail.fm> - 2016-09-27 06:20 +0200
      Re: Substring search in dash [ _NOT_ bash ] shell David <bouncingcats@gmail.com> - 2016-09-27 10:00 +0200

#172814 — Re: Substring search in dash [ _NOT_ bash ] shell

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2016-09-26 17:50 +0200
SubjectRe: Substring search in dash [ _NOT_ bash ] shell
Message-ID<slGki-5BO-5@gated-at.bofh.it>
On Mon, Sep 26, 2016 at 10:39:59AM -0500, Richard Owlett wrote:
> #      string if [ "`hostname`" = bob ]; then echo bob.cfg; fi
> 
> I need for the case when evaluates to marybobsam .
> I can find examples in bash shell, but I need dash.

Are you asking how to check for the substring "bob" in your input,
in POSIX sh?  Use case, and a glob:

case $input in
  *bob*) echo "Bob found." ;;
esac

case $(hostname) in
  *bob*) echo "I must be a Bob." ;;
esac

[toc] | [next] | [standalone]


#172832

FromRichard Owlett <rowlett@cloud85.net>
Date2016-09-27 06:00 +0200
Message-ID<slRIJ-4r1-9@gated-at.bofh.it>
In reply to#172814
On 9/26/2016 10:42 AM, Greg Wooledge wrote:
> On Mon, Sep 26, 2016 at 10:39:59AM -0500, Richard Owlett wrote:
>> #      string if [ "`hostname`" = bob ]; then echo bob.cfg; fi
>>
>> I need for the case when evaluates to marybobsam .
>> I can find examples in bash shell, but I need dash.
>
> Are you asking how to check for the substring "bob" in your input,
> in POSIX sh?  Use case, and a glob:
>
> case $input in
>    *bob*) echo "Bob found." ;;
> esac
>
> case $(hostname) in
>    *bob*) echo "I must be a Bob." ;;
> esac
>
>

Thank you. I was expecting an if...fi construct.
Is dash documented anywhere?
All I've found are pages saying that some "bashisms" do not work 
in dash :<

I've no experience with bash (or any shell) and in any case I'm 
constrained to using dash as I'm working with preseed.cfg .

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


#172833

FromThe Wanderer <wanderer@fastmail.fm>
Date2016-09-27 06:20 +0200
Message-ID<slS25-4Nx-1@gated-at.bofh.it>
In reply to#172832

[Multipart message — attachments visible in raw view] — view raw

On 2016-09-26 at 23:49, Richard Owlett wrote:

> On 9/26/2016 10:42 AM, Greg Wooledge wrote:
>
>> On Mon, Sep 26, 2016 at 10:39:59AM -0500, Richard Owlett wrote:
>>
>>> #      string if [ "`hostname`" = bob ]; then echo bob.cfg; fi
>>>
>>> I need for the case when evaluates to marybobsam .
>>> I can find examples in bash shell, but I need dash.
>>
>> Are you asking how to check for the substring "bob" in your input,
>> in POSIX sh?  Use case, and a glob:
>>
>> case $input in
>>    *bob*) echo "Bob found." ;;
>> esac
>>
>> case $(hostname) in
>>    *bob*) echo "I must be a Bob." ;;
>> esac
> 
> Thank you. I was expecting an if...fi construct.

Some such thing could be used when checking for an exact string, but for
substring matching, the example given is better.

> Is dash documented anywhere?
> All I've found are pages saying that some "bashisms" do not work 
> in dash :<

The dash manual page ('man dash') seems fairly comprehensive, on brief
observation. It doesn't seem as lengthy or as detailed as the bash man
page (which I _have_ actually read full-length, believe it or not), but
it does seem to cover most things.

-- 
   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man.         -- George Bernard Shaw

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


#172837

FromDavid <bouncingcats@gmail.com>
Date2016-09-27 10:00 +0200
Message-ID<slVt5-6M7-13@gated-at.bofh.it>
In reply to#172832
On 27 September 2016 at 13:49, Richard Owlett <rowlett@cloud85.net> wrote:
> On 9/26/2016 10:42 AM, Greg Wooledge wrote:
>> On Mon, Sep 26, 2016 at 10:39:59AM -0500, Richard Owlett wrote:
>>>
>>> #      string if [ "`hostname`" = bob ]; then echo bob.cfg; fi
>>>
>>> I need for the case when evaluates to marybobsam .
>>> I can find examples in bash shell, but I need dash.
>>
>> Are you asking how to check for the substring "bob" in your input,
>> in POSIX sh?  Use case, and a glob:
>>
>> case $input in
>>    *bob*) echo "Bob found." ;;
>> esac
>>
>> case $(hostname) in
>>    *bob*) echo "I must be a Bob." ;;
>> esac
>
> Thank you. I was expecting an if...fi construct.

Shell programming is an arcane topic full of corner cases and traps for
new players. Thus very often the answers to simple questions are far more
complex than we might expect. Consequently you are unlikely to find any
document that spoon feeds you what you need. Diligence and
apprenticeship is the only way here.

And I have to say too, because you are probably unaware ... Greg is a guru.
Consider yourself blessed to be receiving advice from an expert, without
having made much effort :)

> Is dash documented anywhere?

man dash

> All I've found are pages saying that some "bashisms" do not work in dash :<

And the most useful of those is probably this:
http://mywiki.wooledge.org/Bashism

Also you can read this:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html

Asking #bash on freenode.net is another source of excellent guidance.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web