This is an excerpt from a script I am writing to modify some configuration options in a file:


Code:
"config" )
   full=$FULL_BACKUP
   includedir=$INCLUDE_DIRS
   excludedir=$EXCLUDE_DIRS
   keeplocal=$KEEP_LOCAL_BACKUPS
   localdir=$LOCAL_BACKUP_DIR
   echo "Starting configuration mode for backup.sh..."
   echo "Input the information requested. To leave a setting as is, simply leave it blank."
   echo "Do you want to take full backups of your system? Doing this will create a more complete backup, but will also take longer and will occupy more disk space on your computer and the remote server? Input 1 to take full backups, or 0 if you want to specify what folders to back up."
   echo "Current Value: $full"
   read $style
   if [ "$style" == "" ]; then
      style=$full
   fi
   FULL_BACKUP=$style
   if [ "$style" == "0" ]; then
      echo "Specify a list of folders to backup, separated by spaces (Ex: \"/Users/joe /etc /var\")."
      echo "Current Value: $includedir"
      read $include
***      if [ "$include" == ""]; then
         include=$includedir
      fi
      INCLUDE_DIRS=$include
   fi
   echo "Specify a list of folders to never backup, separated by spaces (Ex: \"/Users/joe /etc /var\"). The backup dir will be added automatically."
   echo "Current Value: $excludedir"
   read $exclude
   if [ "$exclude" == "" ]; then
      exclude=$excludedir
   fi
   EXCLUDE_DIRS=$exclude
   echo "Do you want to save compressed backups on your own computer or delete them upon completion? Input 1 to save backups, 0 to delete them."
   echo "Current Value: $keeplocal"
   read $keep
   if [ "$keep" == "" ];  then
      keep=$keeplocal
   fi
   KEEP_LOCAL_BACKUPS=$keep
   echo "Where on your computer will we save the compressed backup to?"
   echo "Current Value: $localdir"
   read $dir
   if [ "$dir" == "" ]; then
      dir=$localdir
   fi
   LOCAL_BACKUP_DIR=$dir
   echo "FULL_BACKUP=$FULL_BACKUP" > backup.conf
   echo "INCLUDE_DIRS=$INCLUDE_DIRS" >> backup.conf
   EXCLUDE_DIRS="$LOCAL_BACKUP_DIR $EXCLUDE_DIRS"
   echo "EXCLUDE_DIRS=$EXCLUDE_DIRS" >> backup.conf
   echo "KEEP_LOCAL_BACKUPS=$KEEP_LOCAL_BACKUPS" >> backup.conf
   echo "LOCAL_BACKUP_DIR=$LOCAL_BACKUP_DIR" >> backup.conf
   echo "Configuration updated! New settings:"
   echo "Full Backups: $FULL_BACKUP"
   echo "Included Dirs (for Full Backup = 0): $INCLUDE_DIRS"
   echo "Exluded Dirs: $EXCLUDE_DIRS"
   echo "Keep Local Backups: $KEEP_LOCAL_BACKUPS"
   echo "Local Backup Dir: $LOCAL_BACKUP_DIR"
   ;;


I'm getting this error: ./backup.sh: line 45: [: : unary operator expected
Line 45 is the one asterisked in this code.
The idea of the == "" statements is to have a blank input mean inherit old value. Anyone help?
The issue is if the variable is blank, the statement becomes if [ == ]; which isn't valid. You need to use double brackets.
Double brackets? You mean [[ equality ]]?
ACagliano wrote:
Double brackets? You mean [[ equality ]]?

Yep.
Is there a time when you would do that and a time when you would not? Because I applied that to all my conditionals and now I'm getting syntax errors and "command not found"

And here's another problem. I tested changing some of the stuff... and its actually not changing. Somehow, it is always keeping the old configs.
Are you using bash or a bash compatible shell? Also, do you have #!/bin/bash at the top of your script?
Without attempting to debug the script,
SpaceCat wrote:
Also, do you have !#/bin/bash at the top of your script?

This is wrong. It's #!. Putting the # first should be reflexive, since it's a comment character in most scripting languages.
Its #!/bin/bash. And I got it working now.

I am curious also, does tar need to be run as sudo to archive anything higher than what the user it is being run as has access to?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement