Results 1 to 10 of 10

Thread: 19.04 - Why doesn't ~ work?

  1. #1
    GhX6GZMB is offline Iced Almond Soy Ubuntu, No Foam
    Join Date
    Jun 2019
    Beans
    1,093

    19.04 - Why doesn't ~ work?

    When executing this command:

    scrot /home/macro/tmp/clip.png -e 'xclip -selection c -t image/png < $f'

    Everything works 100%.

    But when changing it to this:

    scrot ~/tmp/clip.png -e 'xclip -selection c -t image/png < $f'

    Nothing works at all. I don't understand what's wrong here. Help is highly appreciated


    EDIT: I can narrow it down:
    scrot ~/tmp/clip.png doesn't work.
    scrot /home/macro/tmp/clip.png works perfectly.

    I'm totally stumped here.
    Last edited by GhX6GZMB; September 1st, 2019 at 08:59 PM.

  2. #2
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: 19.04 - Why doesn't ~ work?

    First, if you're doing this with sudo, ~ will point to root's home directory /root.

    If not, what directory do you end up in if you enter "cd ~"?
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  3. #3
    GhX6GZMB is offline Iced Almond Soy Ubuntu, No Foam
    Join Date
    Jun 2019
    Beans
    1,093

    Re: 19.04 - Why doesn't ~ work?

    Quote Originally Posted by SeijiSensei View Post
    First, if you're doing this with sudo, ~ will point to root's home directory /root.

    If not, what directory do you end up in if you enter "cd ~"?
    I'm not doing this with sudo, I'm at home (bash): macro@macro-pc: ~$
    Entering cd ~ lands me in macro@macro-pc: ~$

    This is a mystery to me.

  4. #4
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: 19.04 - Why doesn't ~ work?

    What's the output of "echo ~"?
    scrot ~/tmp/clip.png doesn't work.
    scrot /home/macro/tmp/clip.png works perfectly.
    Define "doesn't work". Do you get any error message?
    What's your shell? i.e. what's the output of "echo $0"?

  5. #5
    GhX6GZMB is offline Iced Almond Soy Ubuntu, No Foam
    Join Date
    Jun 2019
    Beans
    1,093

    Re: 19.04 - Why doesn't ~ work?

    Quote Originally Posted by spjackson View Post
    What's the output of "echo ~"?

    Define "doesn't work". Do you get any error message?
    What's your shell? i.e. what's the output of "echo $0"?
    echo ~ gives /home/macro

    echo $0 gives /bin/bash

    "doesn't work" means nothing happens. With the full path I get a screenshot in /home/macro/tmp, with ~/tmp I get... nothing. No error messages, nothing.

    I'll now do a HDD search for "clip.png", perhaps that'll bring something.

  6. #6
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: 19.04 - Why doesn't ~ work?

    Quote Originally Posted by ml9104 View Post
    echo ~ gives /home/macro
    Good. This shows that tilde expansion is operating correctly.
    Quote Originally Posted by ml9104 View Post
    echo $0 gives /bin/bash
    Good. This explains why tilde expansion is operating correctly: we have normal bash behaviour.

    Quote Originally Posted by ml9104 View Post
    "doesn't work" means nothing happens. With the full path I get a screenshot in /home/macro/tmp, with ~/tmp I get... nothing. No error messages, nothing.

    I'll now do a HDD search for "clip.png", perhaps that'll bring something.
    Tidle expansion means that the 'scrot' program is seeing an identical argument in both cases, provided of course that we don't have any non-displayable characters involved and neither aliasing nor shell functions are involved.

    So, if it is indeed the case that
    Code:
    scrot /home/macro/tmp/clip.png
    creates the file /home/macro/tmp/clip.png and
    Code:
    scrot ~/tmp/clip.png
    does not create the file /home/macro/tmp/clip.png then I have no further ideas, I'm afraid.

  7. #7
    Join Date
    Jun 2007
    Beans
    17,337

    Re: 19.04 - Why doesn't ~ work?

    Nothing to do with scrot, just lose the ~/
    Your terminal prompt is already at home directory (i.e ~/), so not needed.

    Code:
    scrot tmp/clip.png

  8. #8
    GhX6GZMB is offline Iced Almond Soy Ubuntu, No Foam
    Join Date
    Jun 2019
    Beans
    1,093

    Re: 19.04 - Why doesn't ~ work?

    Quote Originally Posted by mc4man View Post
    Nothing to do with scrot, just lose the ~/
    Your terminal prompt is already at home directory (i.e ~/), so not needed.

    Code:
    scrot tmp/clip.png

    @mc4man: Brilliant!

    My screen capture now works 100% with all users after dropping ~/ and just using clip.png as the target file name for scrot. The file lands in the home directory of the user every time.

    Thank You x100!

    I still don't understand the problems with ~/ but that's an issue for the gurus.

  9. #9
    Join Date
    Dec 2014
    Beans
    2,566

    Re: 19.04 - Why doesn't ~ work?

    If this is related to your previous question and you're executing those commands from a keyboard shortcut then it's not surprising that the variant with '~/' doesn't work. Tilde-expansion is done by the shell. There's no shell involved when executing commands from keyboard shortcuts, so the tilde does not get expanded. You could work around that by explicitly calling a shell in your shortcut definition and passing the command as a parameter
    Code:
    bash -c "scrot ~/tmp/clip.png -e 'xclip  -selection c -t image/png < $f'"
    but since it works without this I wouldn't bother.
    Holger
    Last edited by Holger_Gehrke; September 3rd, 2019 at 07:07 PM. Reason: Link to old question

  10. #10
    GhX6GZMB is offline Iced Almond Soy Ubuntu, No Foam
    Join Date
    Jun 2019
    Beans
    1,093

    Re: 19.04 - Why doesn't ~ work?

    @Holger:

    Thank You for your feedback. Yes, it's related to my previous question, but I now have a perfectly working solution

    For a newbie, the differences between a shell and the system is very difficult to understand. Your explanation makes perfect sense, but for myself is getting there difficult.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •