Web lists-archives.com

Re: shell script problem

On Wed, Feb 06, 2019 at 02:22:35PM +0900, John Crawley wrote:
> On 06/02/2019 03.17, ghe wrote:
> > On 2/5/19 9:19 AM, Jude DaShiell wrote:
> > > Have you tried replacing "-" with \45 yet?  That's the ascii equivalent
> > > for "-'.
> > 
> > Excellent idea. But:
> > 
> > root@sbox:~# systemctl unmask \45.mount
> > Unit 45.mount does not exist, proceeding anyway.
> > 
> > (Same with quotes.)
> > 
> You might try
> root@sbox:~# systemctl unmask $'\45'.mount
> Just a thought.

You're all just making stuff up without understanding it.

First of all, the ASCII value of - is 45 decimal, or 055 octal, or 0x2d
hexadecimal.  If you use bash's $'\...' quoting syntax, you get to choose
between octal and hexadecimal, the default being octal.

So, $'\055' is equivalent to '-'.  $'\45' is a percent sign.

Second, whatever form of quoting you use in your shell command is simply
a mechanism to make sure your intended arguments get passed to the
command you're invoking.  Once the shell has parsed your quoting, the
quotes are removed.  The command doesn't see them.

As arguments, - and "-" and '-' and $'-' and $'\055' and $'\x2d' are all
exactly the same.  There is no difference at all.

wooledg:~$ args - "-" '-' $'-' $'\055' $'\x2d'
6 args: <-> <-> <-> <-> <-> <->

The command (mount, umount, systemctl unmask, or whatever) does not know
or care which kind of quoting, if any, you used in your shell.

This is also why the classic Unix shell FAQ "how do I remove a file whose
name starts with -" is such a puzzler for many people.  People think
that by quoting the leading - they will somehow make rm treat it as a
filename instead of an option.  But because of how shells *work*, the
quotes are removed, and rm has no idea that you quoted it.

Answer to the FAQ: you must tell rm that this argument is a filename
and not an option.  You do that by putting the end-of-options indicator --
before the filename.  E.g. rm -- -myfile

Another way to do it is to give rm a pathname that does not begin with 
a - character.  E.g. rm ./-myfile

The latter only works because the argument to rm *is* a pathname,
and relative pathnames can have a leading ./ prepended to them without
changing their meaning.

Now, I don't know how systemctl unmask works.  You can try putting --
before your unit argument, if the unit name truly begins with a -,
and see if that helps.  Or, you can try to figure out whether this is
really the correct unit name at all.  It seems rather dubious.

Is there any chance that your fstab file is simply malformed, and is
being converted into bogus .mount units?  Maybe you should go through
your /etc/fstab and look for errors.