Results 1 to 10 of 10
I have a requirement to write a shell script to be able to create a directory with the current date in the format of YYYYMMDD. I need to be able ...
- 02-23-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 4
Create Directory
I have a requirement to write a shell script to be able to create a directory with the current date in the format of YYYYMMDD. I need to be able to pass the directory to the script as a parameter.
I have the script below but it's obviously not correct as it doesn't work. The code below is in a file called test.sh
I'm a nebiew to Linux and wish to learn shell scripting. Your help for this requirement will be appreciated.
DIR=$1
echo "Creating $DIR"
var_date=date +%Y%m%d
DIR/var_date
- 02-23-2010 #2
Just to be complete, I should say that homework questions are not allowed on the forums. It's one of the rules.
however I'll help guide you in the right direction.
var_date=date +%Y%m%d
is literaly making your variable the string
"date +%Y%m%d"
you need to make the shell execute the command, and replace your string with the return of that command.
I suggest reading
Advanced Bash-Scripting Guide
a very good guide to bash scripting.
the section on command substitution should help you.New to the internet, technical forums, or the hacker / open source community??
Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html
RHCE for RHEL version 5
RHCT for RHEL version 4
- 02-23-2010 #3Just Joined!
- Join Date
- Feb 2010
- Posts
- 4
What on earth do you mean by homework questions? This is a legitimate work related requirement I have!
You have confused me totally!
- 02-23-2010 #4
we tend to get quite a few homework questions, especialy from people with low post counts. So I wanted to make sure you knew the rules. You didn't put what this was for, just that you "have a requirement", which sounded like it could have been a homework question. I wasn't trying to be rude or deny you anything (I posted exactly what you need to know, and where your problem was), I just wanted to make sure you knew the restriction in case you were posting homework.
Sorry if I jumped the gun, but I had just finished reading a post that was closed for being homework when the question was very similar to this one.
I'd still recomend my same suggestion, look at the guide I posted, and read that section.New to the internet, technical forums, or the hacker / open source community??
Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html
RHCE for RHEL version 5
RHCT for RHEL version 4
- 02-23-2010 #5
No reason to get too jumpy. It does look like a homework question, so meton_magis was just being careful.
meton_magis is correct about the problem of the name of your directory. You need to actually execute the "date" command, and the guide he posted will help you to do that. It is an excellent guide, and I suggest you read it.
Another issue that you will encounter is that you aren't actually creating a directory anywhere. That requires the use of the "mkdir" command. You can check the man page for "mkdir" (run the command "man mkdir" from a terminal) to get more information on how "mkdir" works.DISTRO=Arch
Registered Linux User #388732
- 02-23-2010 #6Just Joined!
- Join Date
- Feb 2010
- Posts
- 4
Yes meton you did jump the gun a little. I have just joined the forum thats why I have a low post count, get it?
Remember, I'm a rookie to linux and I will need help hence the username "LinuxRooky".
This isn't a warm & friendly welcoming to this linux forum and it's more than obvious that I'm a thorn in your side/s.
So if thats the case then you need to be more honest and say that exactly and trust me I will leave you alone, just be honest!
- 02-24-2010 #7
I wasn't implying in any way that you are a thorn in my side. I did post help for you didn't I? If I thought you were an annoyance, I would have just closed my browser and not helped you.
I'm not sure what kind of warm and friendly welcome you're expecting, but I'm just not that kind of person. I see a problem, and I try to fix it. There are plenty of people on the forum who will chat with you, but I'm not the kind of person who strikes up conversations in the middle of threads. If you had posted something to the tune of " Hi how's it going?" I probably would have responded differently. But you posted a request for help, so I focused on that. That's just who I am, sorry.
I do however take offense to the implication that I've been anything but honest. There may have been a misunderstanding, which I immediately tried to clear, but I have done nothing to warrant you questioning my honesty. I already apologized for jumping the gun, even though if you read carefully, you'll see that I never accused you of doing anything wrong. I just restated the rule, in case you were not aware of it. If I had truly thought you were trying to subvert the rules, I would have just ignored you and waited for a mod to close your thread.
I'm sorry if you took offense to anything I said, but realize that anyone who helps you out on here is doing so from their own time. I haven't seen more than a couple people on here who try to be jerks, and those few are banned pretty fast.New to the internet, technical forums, or the hacker / open source community??
Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html
RHCE for RHEL version 5
RHCT for RHEL version 4
- 02-24-2010 #8
LinuxRooky, meton_magis was correct to inquire whether this was a homework question as we DO get a lot of them. I thought the same thing when I read your initial post. Home work questions are against the rules and meton_magis was only trying to abide by our policies. Subsequently, he has been more than accommodating and apologetic toward you. No one here is required to help you or anyone else. If you want to be treated with respect and consideration, try showing a little in return and stop making baseless accusations. Do this and you'll be surprised at how much help you'll get and it's all free.
- 02-24-2010 #9Just Joined!
- Join Date
- Feb 2010
- Posts
- 4
Its more than obvious that those that have replied negatively so far are a bunch of LOSERS!
So long LOSERS!
- 02-24-2010 #10
I don't believe that anyone did anything wrong here, but I'll go ahead and close this thread. LinuxRooky, if you do decide to stay at the forum, please do understand that no one here was being rude: we were just checking if your question was a homework question, because we get a lot of them here.
DISTRO=Arch
Registered Linux User #388732



