LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-12-2010, 12:43 PM   #16
Pocho
LQ Newbie
 
Registered: Aug 2010
Posts: 4

Original Poster
Rep: Reputation: 0

Thx for ur answers guys, i'll look into it, now with the points u make grail

Quote:
1. Your code makes no attempt to single out files only, so what about directories? If you run 'rm -f' on a directory you will get an error.

2. answer2 is requesting input from a user but you make no attempt to sanitize it. Also, what of the simple option of the difference between Y and y.

3. Also on answer2, what happens if the user accidentally or on purpose just presses enter? (ie variable is now not set)
this is the first class that we had doing bash programs so im still a big noob on it, i really dont know how will i single out files and leave directories alone so i dont get errors. on ur second point, what u mean by sanitize it? sorry again Noob in the house so i really dont get what u mean. With the "y" and "Y" difference i guess that will b just adding and "or" statement in the beginning of the "if" statement right? if the user where to imput and empy value mmmmmm i was thinking maybe i could solve that problem adding another "if" after the first request for input? u know something like if the input != yyyy-mm-dd go back to the begining or something like that, would that work or am i totally incorrect here?

About the delete.list file that is generated, i read the homework over and over and it just say created a file with the output, nothing else so i take it he just wants us to practice with the redirective output to a file. Oh for right now the code will b run inside a specific folder and in a control environment so this should meet the requierements of the homework, but i definitely want to make it better so i'll keep working on it and trying to figure out and apply u guys input on this, after all i do want to learn to do it right =)
 
Old 08-13-2010, 02:32 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,565

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Hey Pocho

All cool that you are just starting (we all have at some point ).

Here are some points to help you on your way:

1. test and [ are synonymous (ie do the same thing), so if you look up your books or associated bash website have a look at the section on testing, specifically the -d and -f options (there are others for files but will let you find them out). Also, if you do a 'man test' the information is there as well.

2. sanitizing is meant in the way in which you make sure you are getting your desired input. ie the date is in the order you require and the user has entered Y or y.

3. Your extra 'if' idea for testing a null variable will fail just as poorly I would recommend looking up the difference between [ and [[ and again some test options such as -n or -z

4. Last I would mention that instead of multiple 'if' statements you may wish to lookup the 'case' statement

Finally, good luck and hope you get into it
 
Old 08-13-2010, 08:45 AM   #18
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Hi grail
Quote:
Originally Posted by grail View Post
1. test and [ are synonymous (ie do the same thing), so if you look up your books or associated bash website have a look at the section on testing, specifically the -d and -f options (there are others for files but will let you find them out). Also, if you do a 'man test' the information is there as well.
For information on the bash built-in test, use help test.

man test will describe the external command test, usually /bin/test, which may not behave exactly like the bash built-in test.
Quote:
Originally Posted by grail View Post
3. Your extra 'if' idea for testing a null variable will fail just as poorly I would recommend looking up the difference between [ and [[ and again some test options such as -n or -z
In bash, an unset or null variable is false so no test operator such as -n or -z is needed. To illustrate:
Code:
c@CW9:~$ unset foo
c@CW9:~$ [[ $foo ]] && echo true || echo false
false
c@CW9:~$ foo=
c@CW9:~$ [[ $foo ]] && echo true || echo false
false
c@CW9:~$ foo=abc
c@CW9:~$ [[ $foo ]] && echo true || echo false
true
If [[ $foo ]] is replaced with [ $foo ] or test $foo the output is the same.
 
Old 08-13-2010, 10:07 AM   #19
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,565

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
@catkin - thanks for the correction on the individual tests although the output of -n or -z on your tests will yield different results especially if you compare using either the single or double square brackets:
Code:
~$unset foo
~$[ -n $foo ] && echo true || echo false
true
~$[[ -n $foo ]] && echo true || echo false
false
~$[ -z $foo ] && echo true || echo false
true
~$[[ -z $foo ]] && echo true || echo false
true
 
  


Reply

Tags
delete


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash: How to grep stdout? ryan858 Programming 4 06-05-2010 11:17 AM
bash script and grep inside file? agrinog Programming 3 04-02-2010 03:26 PM
Grep in bash script returns "No such file or directory", works manually gizza23 Programming 7 02-25-2010 05:37 PM
Bash: using file as input for grep/tail and then some.. sleipnir Programming 5 06-18-2009 05:51 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 12:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration