Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:45:26+00:00 2026-06-17T04:45:26+00:00

#!/bin/bash while read -r line; do mkdir UNIX/$line done < usernames.lnk MasterDir=/home/darkeve/Documents/OS/master/ USERHOME=/home/darkeve/Documents/OS/UNIX for

  • 0
#!/bin/bash
while read -r line; do
    mkdir "UNIX/$line"
done < usernames.lnk

MasterDir="/home/darkeve/Documents/OS/master/"         
USERHOME="/home/darkeve/Documents/OS/UNIX"            

for FILENAME in `cat $MasterFile`
do
    cp $MasterDir/$FILENAME $USERHOME/$USER
done

My script does the first job right, it first reads a file called “usernames” and creates individual folders for each user into the UNIX folder. But it is then supposed to copy 3 files from the master folder called “file1, file2 and file3” and copy them into each individual user folder in the UNIX folder but it simply doesn’t do that. Any help would be appreciated.

p.s. I am very new to scripting so please keep it simple.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:45:27+00:00Added an answer on June 17, 2026 at 4:45 am

    Your current script uses $USER in cp command, which is ‘user running the script’ and not read from usernames.lnk. If you want to copy to each individual folder you need to put for-loop inside first while loop and use $line as destination folder name, like this:

    #!/bin/bash
    MasterDir="/home/darkeve/Documents/OS/master/"         
    USERHOME="/home/darkeve/Documents/OS/UNIX"   
    MasterFile="filenames.txt"
    
    while read -r line; do
        mkdir "UNIX/$line"
        for FILENAME in `cat $MasterFile`
        do
            cp "$MasterDir/$FILENAME" $USERHOME/$line
        done
    done < usernames.lnk
    

    It’s usually a good idea to simply echo things when you are not sure what goes wrong, you can try e.g.

    echo "$line" 
    echo "$USER"
    

    and so on to see the difference on these variables.

    Also, $MasterFile is not defined in your script. It should be introduced same way than MasterDir and USERHOME in the beginning.

    Edit: I added it in the script example, please change it to correspond with your file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following bash script: #!/bin/bash FILE=p.txt while read line; do export http_proxy=http://$line
I have this simple script: #!/bin/bash cmd=file.txt while read line do command $line >
I have code like this, which processes a CSV file: #!/bin/bash while read line
#!/bin/bash #James Kenaley 20120513 #Server Monitor Script while read -r name ip content do
I have this code: #!/bin/bash input=./user.cvs while IFS=';' read -r f1 f2 f3 f4
#test code: #!/bin/bash #~/test/test.sh trap echo 'testmessage' DEBUG while : do echo abc sleep
#!/bin/bash echo SCRIPT: $0 echo Enter Customer Order Ref (e.g. 100018) read P_CUST_ORDER_REF echo
#!/bin/bash echo 'first line' >foo.xml echo 'second line' >>foo.xml I am a total newbie
Not sure why the last line does not cut the from the script: #!/bin/bash
I have a code snippet, as follows. #!/bin/bash filename=tmp_list_filenames line_index=0 cat $filename | while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.