Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

I can't get bash script to store value into variable on my Solaris System but works fine on all other LInux Flavors

Hello, I am new to Sun Solaris. I like it so far but I am having problems with some of my bash scripts.

I am trying to run a backup script which does a system call and stores that value into a variable. If I run this command in the shell it works perfectly fine. But if I put the same command in a shell script it gives me an error. The following commands work just fine in my shell scripts on my red hat and debian servers.

LIST="$(ncftpls -u vivek -p mypassword ftp://array05.wan.nixcraft.com/vivek/)"
NOW=$(date +"%d-%m-%Y")
DAY=$(date +" %a" )

If I run them at the terminal window they store the proper value in teh variable if I echo it. But if i put it in a script it gives me an error like below:


bash-3.00# sh FTP_BACKUP_SCRIPT_v1.2.sh
FTP_BACKUP_SCRIPT_v1.2.sh: syntax error at line 8: `NOW=$' unexpected

Any idea why? Is processed differently on Sun Solaris and if so how can i fix this. Thanks!

0
nichiaiinc
Asked:
nichiaiinc
1 Solution
 
ozoCommented:
maybe you should  try
bash FTP_BACKUP_SCRIPT_v1.2.sh
0
 
nichiaiincAuthor Commented:
Right on! That was it. I have always been calling the script using sh for about two years without any problems. Thanks to Solaris for showing me what i was doing wrong and you for the answer. it works now!
0
 
Adam314Commented:
If you put this as the first line in your script:
  #!/bin/bash

Then you can call the script with just:
     FTP_BACKUP_SCRIPT_v1.2.sh

Or, if the script is not in your PATH:
    /path/to/FTP_BACKUP_SCRIPT_v1.2.sh
Or, from the current directory:
    ./FTP_BACKUP_SCRIPT_v1.2.sh


0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now