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

  • Home
  • SEARCH
  • 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 6584665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:33:55+00:00 2026-05-25T16:33:55+00:00

I’m trying to write a Linux Shell Script to do some automation on my

  • 0

I’m trying to write a Linux Shell Script to do some automation on my server. I’m using Ubuntu 11.04 by the way.

Basically, the process is as follows:

A. I create multiple text files using PHP in a directory (/home/mydir). These text files are stubs of a shell script, and they contain only variable definitions. Here is a sample of what might be in one of the files.

username="myusername1"
password="mypassword1"
othersettings="othersettings1"

B. I have a setup shell script that references the above variables. Below is a part of what may be in the script:

#!/bin/bash
mkdir /home/newdir/$username

I’m trying to write an activation shell script that will find out how many of these files are in the /home/mydir and then execute the setup shell script for each one of the files in the directory. So, for example, if I have 5 files with 5 different username, password, etc. the setup script will be run 5 times using the variables in each of the text files to complete the tasks defined in this script.

I’d appreciate some assistance on how to write such a script. The way my mind is working is that I should use maybe ls -1 /home/mydir | grep .txt to get all txt files, then extract them to an array, and then iterate and execute the script, but I’m not a shell scripting expert so I need some assistance with the syntax. If shell scripting was PHP, it wouldn’t have been a problem for me, but alas, it is not.

Thanks in advance.

  • 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-05-25T16:33:56+00:00Added an answer on May 25, 2026 at 4:33 pm

    The way to do this in shell is something like this:

    for f in /home/mydir/*.txt; do
        . "$f" # source settings file
        mkdir "/home/newdir/$username"
    done
    

    But as I mentioned in my comment, you could just write your script in PHP.

    #!/usr/bin/php
    <?php
    ...
    ?>
    

    EDIT

    Your code works, I just edited it for calling a shell script within a shell script, which is what I really wanted to do. So the below code works too.

    #!/bin/bash
    for f in /home/dir/*.txt
    do
       . "$f"
       . /path/to/setup-shell-script #referenced in B of the original question
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.