Linux: Create file with .sh script containing username

Posted on 2011-10-12
Last Modified: 2012-05-12
I want a .sh script that will create a new file named "me.txt" and that new file should contain the username of the user who ran the script.
Question by:hankknight
    LVL 13

    Expert Comment

    by:Hugh McCurdy
    Try something like in this example

    echo "Testing" > "$USER".txt

    Open in new window

    LVL 13

    Accepted Solution

    Wait, you want the file to contain the user name.  OK try this

    echo "My user name is $USER" > me.txt

    Open in new window


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now