All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guido Berhoerster <guido+kernel.org@berhoerster.name>
To: dash@vger.kernel.org
Subject: Re: Replacement for declare in dash?
Date: Wed, 16 Oct 2013 15:09:56 +0200	[thread overview]
Message-ID: <20131016130956.GI19570@hal.local.invalid> (raw)
In-Reply-To: <20131016121859.GA30169@yade.xx.vu>

* Alexander Huemer <alexander.huemer@xx.vu> [2013-10-16 14:26]:
> Hi,
> 
> I wrote a shell script on a non-Debian system and assumed, in my 
> greenness, that testing it with #!/bin/bash --posix would ensure that 
> the script would run under dash too. I was wrong. Of course that is the 
> fault of bash and not dash.
> Here is a simplified form of the script:
> 
> #!/bin/dash
> # This works when run with #!/bin/bash --posix
> 
> func() {
>         cat /proc/1/environ
> }
> 
> sudo sh -c "$(declare -f func); func"
> 
> Can I do anything equivalent with dash?

No.

> I did not find anything in the docs, but hope dies last.

This is even ugly in bash because you're abusing a function as a
variable. And the shell you get with "sudo sh" depends on your
system configuration.
You can embed commands using a here-doc instead of func()...

sudo /bin/dash << "EOF"
cat /proc/1/environ
# ...
EOF

> Of course I can swap the function out in a seperate script, but I'd like 
> to avoid that.

...but this seems to be the right thing to do rather than
embedding a script inside a script.
-- 
Guido Berhoerster

  reply	other threads:[~2013-10-16 13:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-16 12:18 Replacement for declare in dash? Alexander Huemer
2013-10-16 13:09 ` Guido Berhoerster [this message]
2013-10-16 14:17 ` Chet Ramey
2013-10-16 14:41   ` Eric Blake
2013-10-16 15:34   ` Alexander Huemer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131016130956.GI19570@hal.local.invalid \
    --to=guido+kernel.org@berhoerster.name \
    --cc=dash@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.