LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-25-2011, 07:11 PM   #1
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Rep: Reputation: Disabled
Some annoying output - something small, just cannot see what?


removed

Last edited by Batistuta_g_2000; 10-31-2011 at 06:08 PM.
 
Old 10-25-2011, 07:39 PM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
Hi again Batistuta,

Your script has some structural problems. Here is my interpretation of what I think you're getting at:

Code:
#!/bin/bash
# ... blah blah ...
# ... find command here ...
retval=$?

if [ $retval -eq 0 ]; then
    echo "Do backup stuff"
else 
    perror $retval
fi

exit $retval
 
Old 10-25-2011, 07:58 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
...even worse using 'find -L */"$filename";' definitely isn't the right way: either make the user supply the full path, a search path or search the local directory (use 'optargs'?). Then $filename isn't propagated down the script so 'echo "file "$filename" found;' doesn't even show the actual file (or files!) found and it doesn't protect against spaces and such. And usually you have an idea of which files to back up. I mean you don't go backing up random files.

Code:
function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/ 
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq 
http://wooledge.org/mywiki/BashPitfalls"; }
 
Old 10-26-2011, 06:40 AM   #4
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
removed

Last edited by Batistuta_g_2000; 10-31-2011 at 06:09 PM.
 
Old 10-26-2011, 04:33 PM   #5
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
Batistuta,

It's coming along, keep up the effort! A few things.

Your if statements are still not correct, but they're closer. Please see my other post.

Here's a marked up version, discussing a few of the issues:

Code:
#!/bin/bash

# This find command looks for a file named retval.
find retval

# So this is probably going to set the variable retval to 1, not 0 (true.)
retval=$?

if [ $retval -eq 0 ]; then
    echo "Do backup stuff [y/n]"
     read yn
      # the second 'if' is out of flow.
      # You should at least quote (with ") your variables.
      if [$yn = y] || if [$Y = Y] 
         # "do" is for loops, not for the if statement. See the man page.
         do "Blah"
      # Why not just use an else statement?
      # This is the correct way to use || with two expression clauses, though.
      elif [$yn != y] || [$yn != Y]
         # see above comment about do.
          do Exit
      fi
else 
    # You're missing an echo call.
    "not found exiting"

fi

exit $retval

Another free tip: try debugging your scripts by adding set -x to the top.

Here's another revision that should do what you want.

Code:
#!/bin/bash

set -x

# Assume you run some find command that returns 0, here we mock up with the 'true' binary.
true
retval=$?

if [ $retval -eq 0 ]; then
    echo "Do backup stuff [y/n]"
    read yn
    do_backup=$(echo "$yn" | grep -c '^[yY]$')

    if [ $do_backup -eq 1 ]; then
        echo "Doing backup stuff..."
        # Do the backup stuff.
    else
        echo "Okay, bye."
    fi
else  
    echo "Couldn't find any files."
fi

exit $retval

Last edited by jhwilliams; 10-26-2011 at 04:39 PM.
 
Old 10-27-2011, 02:58 PM   #6
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
removed

Last edited by Batistuta_g_2000; 10-31-2011 at 06:09 PM.
 
Old 10-28-2011, 09:27 PM   #7
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
removed

Last edited by Batistuta_g_2000; 10-31-2011 at 06:09 PM.
 
  


Reply


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
small annoying problems with my slackware build danyboy25 Slackware 27 05-12-2010 09:04 AM
Xubuntu 8.04 small but annoying problem (for me) rabbitnightmare Linux - Newbie 1 05-06-2008 03:23 PM
an annoying small T nmansour Programming 8 08-15-2007 10:55 AM
Small, but annoying SuSE/KDE problem joecloud SUSE / openSUSE 1 10-21-2004 10:01 PM
small but annoying problem in mandrake 9.1 with KDE calimer Linux - Software 1 05-25-2003 10:41 PM


All times are GMT -5. The time now is 06:42 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