Again I need your explaination to understand a program.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Rep:
Again I need your explaination to understand a program.
[ The name of this program is temp30.]
#!/bin/sh
echo "File Name\tType"
for i in *;
do
echo "$i\t\c"
if [ -d $i ]; then
echo "directory"
elif [ -h $i ]; then
echo "symbolic link"
elif [ -f $i ]; then
echo "file"
else
echo "unknown"
fi
done
for i in *;
do
printf "%32s " "$i"
if [ -d "$i" ]; then
echo "directory"
elif [ -h "$i" ]; then
echo "symbolic link"
elif [ -f "$i" ]; then
echo "file"
else
echo "unknown"
fi;
done
for i in *;
do
printf "%-32s " "$i"
if [ -d "$i" ]; then
echo "directory"
elif [ -h "$i" ]; then
echo "symbolic link"
elif [ -f "$i" ]; then
echo "file"
else
echo "unknown"
fi;
done
printf is indeed used in C, but also in awk, shellscripting, perl and probably lots of other programming 'languages'. In general you can use the C syntax.
For details look at: man 3 printf
To give you a bit of a headstart:
32 => width of the field. In this case "File Name" is placed in the 32 char field, alligned to the rigth side.
-32 => same as above, except that "File Name" is alligned on the left.
The parts between % and s (including) define your format. %s being the most basic (s can be different, see manpage for details). Between the % ans s there can be modifiers. In this example 10 or -15. 10 creates a field that's 10 characters wide, text will be placed on the rigth side. -15 creates a 15 character wide field and places text on the left side (the -).
The \n adds a linefeed, without one your cursor stays on the same line.
Now that you've hit 500 posts, it's time to learn how to ask questions. Writing the same vague question in huge red bold font isn't going to get you more answers. I'd highly recommend reading this guide before posting more questions.
If you're having problems with shell scripts, try the sh man page. This is a nice way of saying RTFM, but unfortunately it's the only type of answer this question should get.
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Original Poster
Rep:
Puffinman
Those man pages are not written for the laymen. I am a beginner. Those man pages have not written in a manner to address the problems facing a beginner.
I believe you are an advanced person in these programming.
My knowledge of progrmming is not good like you all.
The bottom line is that man pages are difficult for me to understand.
Yes, it is incorrect to write big letters according to the guide. I did that as I havn't received a positive reply for a few hours. I must learn those posted problems before going further. I am studying using some online teaching materials.
I will try my level best to refrain from writing big letters in the future.
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Original Poster
Rep:
Druuna
Now I understand more. Thanks for helping me. I have a smattering of knowledge when it comes to these scripting. Those man pages are not written in user friendly manner. You explain to me in a very simple manner.
Those man pages are for the advanced programmers. I will be posting more.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.