Find the answer to your Linux question:
Results 1 to 5 of 5

Thread: bash question

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    bash question

    I am trying to write a bash script that checks for a directory and if the directory is not there creates it. I have everything written but I have no idea how to have bash check for a directory.


    if [/Library/Admin Is not there]; then
    mkdir /Library/Admin

    can't figure out the part between the [].

    Thanks. for the help.

  2. #2
    Linux Guru sarumont's Avatar
    Join Date
    Apr 2003
    if [[ -e $1 ]]
            then echo "Directory Exists."
            else mkdir $1
            echo "Directory Created."
    That will do it with a command line arg. for the directory that you want to check.
    "Time is an illusion. Lunchtime, doubly so."
    ~Douglas Adams, The Hitchhiker's Guide to the Galaxy

  3. #3

    logging in user

    I have another bash script that runs at login and is supposed to get the username of the person that is logging in, but it doesn't do it. However, if I run the script from the terminal after I have logged in it gets the username of the person logged in.

    here is what I use to get the username
    LOGINNAME=`/usr/bin/who | /usr/bin/grep console | /usr/bin/awk '{ print $1 }'`

    How can I get the username as they are logging in and not after they have logged in?


  4. $spacer_open
  5. #4
    Linux Guru
    Join Date
    Mar 2003
    The problem is you're running your script before you're actually logged in.

    Try putting the call to your script as close to the end as possible in the .bash_profile file. If that doesn't work, try it in the .bashrc file...

    I know there's a gui equivilent to .bash_profile, like one of those rc files. I'll see if I can't find it.

    Or you might try a sleep command. I'm not sure if that would make your entire login pause until the command is finished executing or not. If it doent, you can make it sleep for like a minute or two until the login process is finished.

    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

  6. #5
    You could use the command:
    LOGINNAME=`id -un`

Posting Permissions

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