Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2008-10-28
3
438 Views
Last Modified: 2013-12-27
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
Comment
Question by:nichiaiinc
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 22820536
maybe you should  try
bash FTP_BACKUP_SCRIPT_v1.2.sh
0
 

Author Comment

by:nichiaiinc
ID: 22820887
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
 
LVL 39

Expert Comment

by:Adam314
ID: 22822907
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question