1

So, I have a script that uses -S mount nfs -o proto=tcp,port=2049 … etc. to mount a location from another Linux computer. What does -S mean? It seems to work just fine with or without it (it doesn't work if I do such as gksu -- -S mount … etc. to launch it without a terminal emulator). I'm curious if I actually need -S for some reason, or if I can drop it to make gksu -- work, without consequences.

Here's the script I wrote, for reference, with the IP address and paths changed to protect the paranoid:

#!/bin/bash

if mountpoint -q /home/myLaptop/myDesktop
then
  notify-send -t 3000 "Warning" "It is already mounted."
else
  gksu -- -S mount -t nfs -o proto=tcp,port=2049 192.168.0.x:/home/myLaptop /home/myLaptop/myDesktop
  if mountpoint -q /home/myLaptop/myDesktop
  then
    notify-send -t 3000 "Alert" "Mounted."
  else
    notify-send -t 3000 "Alert" "Mount failed."
  fi
fi
  • 1
    It just begins with -S? Nothing before? – DisplayName Apr 22 '16 at 19:11
  • Yes. There is nothing before. It's really weird to me. I edited my question and added my script so you can see what's going on. The command works with sudo instead of gksu, and it works without -S (but it won't do gksu and -S together. – Shule Apr 22 '16 at 19:21
  • Check the manpage – Bratchley Apr 22 '16 at 19:21
  • 1
    Although it's a little weird to pass -- and then continue giving gksu options. Usually -- is how a program knows to treat everything afterwards as non-option arguments – Bratchley Apr 22 '16 at 19:23
  • 1
    Yeah it's an option to gksu which explicitly tells it to use sudo rather than su – Bratchley Apr 22 '16 at 19:29
5

-- means “end of options”: subsequent arguments are not considered to be options, even if they start with a dash. This is a quasi-universal convention. So gktu -- -S mount … means to run the command -S.

$ gksu -- -S whoami
sh: 0: Illegal option -S

It seems that you meant to pass the -S option to gksu, to tell it to use sudo rather than su. It needs to come before --.

$ gksu -S -- whoami
root

You do need -- because otherwise gksu would think that the -o option is intended for itself rather than for mount.

  • I didn't mean to pass -S into gksu and I knew what -- was for. I just didn't think of -S as associated with gksu because I was mentally separating the information after it. However, it seems that's what the person who originally wrote the command meant to do. I was trying to understand what -S was for, and why it seemed to begin the command rather than be an argument. I added the -- myself, though. I thought -S was causing the error rather than -o. – Shule Apr 23 '16 at 6:28
  • The confusion came because the code worked with sudo but not with gksu. So, I figured -S must be independent of both. Plus, it didn't make sense to me how -o could be associated with gksu when mount -t nfs is between them. Anyway, I'll accept your answer; I explain everything else here and in the comments to my question anyway. (Plus, I like that you pointed out the -o thing, which wasn't mentioned up until now.) And you do say what -S means, whether or not you assumed I already knew. – Shule Apr 23 '16 at 6:55
  • Someone edited my question title from the original, which is probably why it seemed like I already knew. I don't think the title should have been edited. – Shule Apr 23 '16 at 6:57
  • @Shule The question is completely unrelated to mount. With mount mentioned in the title, people will find this question if they're looking for information about mount, and it won't help them. That's why the title should mention gksu, not mount. I'm going to rollback your edits, because you've made it hard to find by people who're looking for relevant information, and the editorial remark does not belong at the beginning (the beginning of your question is excerpted on the front page, and that doesn't give any information about your question). – Gilles 'SO- stop being evil' Apr 23 '16 at 12:33
  • No offense intended, and if you really want it that way, I'm not going to roll it back again. However, I know it's unrelated to mount. However, the question is precisely for people who think it is related to mount. It won't help other people (who could just check the help for what -S means) much, and they will be confused as to why I'm asking something I already know about. In essence, you're not clarifying the question: You're changing it. Really, the question is about -S independent of gksu and potentially mount and the answer is that it's an argument to gksu and sudo. – Shule Apr 24 '16 at 1:29
0

Because there's some confusion in the other answer I accepted, I'm going to write my own answer which answers precisely what I asked, but I'll leave that one as the accepted answer since it answers the question that my question has been edited to be instead of what it originally was.

-S is not an independent command as was first assumed. It also has nothing to do with mount. It is an argument to sudo and/or gksu (it does something different depending on which command you use). (So, it should be gksu -S -- instead of gksu -- -S.) So, that's what -S means in the sense I was wondering. However, to explain what it means beyond that, I'll quote the help:

  • gksu -S means, 'Make GKSu use sudo instead of su, as if it had been run as "gksudo".'
  • sudo -S means, 'read password from standard input'.

It also appears to be unnecessary to use gksu -S when you can more readably use gksudo instead. sudo -S, on the other hand, may have some importance with passwords.

We just need to run a command as root (not actually be root). So, that's why we use gksudo or gksu -S instead of gksu without -S.

-- still needs to be there, even though -S is part of gksu otherwise -o will be read as an argument to gksu, too.

So, here's the amended code:

#!/bin/bash

if mountpoint -q /home/myLaptop/myDesktop
then
  notify-send -t 3000 "Warning" "It is already mounted."
else
  gksudo -- mount -t nfs -o proto=tcp,port=2049 192.168.0.x:/home/myLaptop /home/myLaptop/myDesktop
  if mountpoint -q /home/myLaptop/myDesktop
  then
    notify-send -t 3000 "Alert" "Mounted."
  else
    notify-send -t 3000 "Alert" "Mount failed."
  fi
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.