Find the answer to your Linux question:
Results 1 to 3 of 3
Okay, well I'm writing a script that has the simple task of downloading an archive, making a directory, and extracting the archive to that directory. The part I'm having trouble ...
  1. #1
    Just Joined! rockinup1231's Avatar
    Join Date
    Feb 2007
    Posts
    16

    Writing a script for more than one user

    Okay, well I'm writing a script that has the simple task of downloading an archive, making a directory, and extracting the archive to that directory. The part I'm having trouble with is writing the part that tells the computer to make a directory. If it were for me alone, I could simply tell it...

    Code:
    mkdir /home/justin/.kde/share/apps/deKorator/themes/
    However, I know that each time it will be used, the user will not be "justin". What could I do to make this command work for anyone that decided to use it? Thanks for any help in advance.

    P.S. I am doing this for multiple purposes. The first being for my own convenience (now and possibly in the future), and for educational purposes (I'm new to writing scripts. I know what to do, but not all the commands). It's basic function will be to install a specific deKorator theme for the user, and also install deKorator and set it up the themes directory (which it doesn't seem to do on it's own).

    EDIT:I just figured it out....I googled it (was trying to before) and found I wasn't asking the right question. I could make said line I mentioned before as

    Code:
    mkdir $HOME/.kde/share/apps/deKorator/themes/

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by rockinup1231 View Post
    EDIT:I just figured it out....I googled it (was trying to before) and found I wasn't asking the right question. I could make said line I mentioned before as

    Code:
    mkdir $HOME/.kde/share/apps/deKorator/themes/
    I am glad that you found your way by yourself.

    I will just add a little tip: when using file and directory names under bash, remember that in linux, names with blank spaces are legal.

    Having a space in your home directory is not usually a good idea, but it's not impossible. So, just to be on the safe side, you should always use double quotes when writing paths of file names, like this:

    Code:
    mkdir "$HOME/.kde/share/apps/deKorator/themes/"
    You can just quote the unknown part, since the rest of the string is well known and you are sure that it doesn't contain spaces:

    Code:
    mkdir "$HOME"/.kde/share/apps/deKorator/themes/
    If you don't quote this, and your home dir is called "Jean Paul", then mkdir will receive two arguments, the first will be "Jean", the second would be "Paul/.kde/share/apps/deKorator/themes/" and you will get "inexplicable" errors.

    That's very unprovable in this case, but since failures in the quotation are one of the most common errors amongst newcomers, I just wanted to let you know about it so you don't get the bad habit.

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    i92 makes an excellent point about quoting, and it is a good one to remember.

    I just want to add that because using your home directory is so common, Bash actually has a shortcut for this: '~' (which you also don't have to quote, which is nice). So your line could also be:
    Code:
    mkdir ~/.kde/share/apps/deKorator/themes/
    And this would be the same as using "$HOME".
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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