Linux - CertificationThis forum is for the discussion of all topics relating to Linux certification.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi I am doing an exercise in an LPI manual which is not very clearly explained. Here is the script. I have inserted comments for each line with my assumptions. I would appreciate if someone could correct or explain these assumptions.
Here is the stand alone code:
for var in arg1 arg2 arg3
do
echo $var
mkdir mydir5[$var]
cd mydir5[$var]
touch myfile5.txt
cd
done
deb1:/home/siawash# for var in arg1 arg2 arg3
# within the users home directory create variables arg1, arg2 arg3 using #a "for" loop
> do
> echo $var
# Then print out each variable name consecutively
> mkdir mydir5[$var]
# create a directory called mydir5. i get confused after this point.
# What is meant to happen with the arg parameters.?? The effect is that I #end up with a directory called mydir5[arg1] in my user's home and myfile5.txt within it and mydir5[arg2], mydir[arg3] in my /root #directory.
# I had the feeling that there should be three directories, each with different parameters..arg1 arg2 arg3 and each with myfile5.txt...am I wrong.?
> cd mydir5[$var]
# I had the feeling this bit is meant to go in mydir5[arg1]
> touch myfile5.txt
# and create myfile5.txt in each directory.
> cd
# Then cd out
##How does the script tell bash to "cd .." and go into /root
##and create mydir5[arg2] mydir5[arg3]
> done
*************************************************************************
Here is the output of that script
arg1
arg2
arg3
*************************************************************************
This is the prompt with the ls output
deb1:/home/siawash# for var in arg1 arg2 arg3
# within the users home directory create variables arg1, arg2 arg3 using #a "for" loop
> do
> echo $var
# Then print out each variable name consecutively
Correct. and correct.
Quote:
Originally Posted by siawash
> mkdir mydir5[$var]
# create a directory called mydir5. i get confused after this point.
# What is meant to happen with the arg parameters.?? The effect is that I #end up with a directory called mydir5[arg1] in my user's home and myfile5.txt within it and mydir5[arg2], mydir[arg3] in my /root #directory.
I would guess you are executing the script as root. Generally not a good idea when you don't understand what the script does. I'm also guessing that the script resides in your user's $HOME.
Since you start in your user's $HOME, the first directory mydir5[arg1] is created there. The first cd at the end of the do loop puts you in /root. The command cd without a path defaults to the user's $HOME. If my guess about you executing the script as root is correct, that's why you end up with the next two directories in /root (root's $HOME).
Yes, you were spot on. Many thanks for your reply!
BTW I notice that LQ has a feature that allows users to thank contributors, but I don't know how I can activate it. Would you be able to help? Kind of embarrassing receiving so much help from so many and not thanked any...
As you can see I clicked on the thumb but my profile still shows zero thanked...
If you check the statistics in your profile, you will notice that you have Total thanks: 1 and Thanked: 0. In your posts you see only the number of received thanks, not the number of given thanks.
Now I thank your post, just to demonstrate that the count increase when you receive thanks from other members. Cheers!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.