Date Call in Script Error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date Call in Script Error
# 1  
Old 03-07-2011
Date Call in Script Error

Hello,

Got a simple script:
Code:
a="Something"
b=$(date +"%y%j")
c="something else"
d="$a$b$c"
echo "$d"

On running it gives the error:
Code:
scripty.sh: syntax error at line 2: `b=$' unexpected

Can't understand it, any ideas?

Last edited by Franklin52; 03-07-2011 at 07:41 AM.. Reason: Please use code tags
# 2  
Old 03-07-2011
When concatenating variables use curly braces.
Code:
d="${a}${b}${c}"

# 3  
Old 03-07-2011
Hi.

This seems for work with bash on GNU/Linux:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate results of bash, date variable setting, display.

# Utility functions: print-as-echo, print-line-with-visual-space.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }

# "context" is a local-only command.
context date echo

pl " Results:"
a="Something"
b=$(date +"%y%j")
c="something else"
d="$a$b$c"
echo "$d"

producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.7 (lenny) 
GNU bash 3.2.39
date (GNU coreutils) 6.10
echo - is a shell builtin [bash]

-----
 Results:
Something11066something else

Best wishes ... cheers, drl
# 4  
Old 03-07-2011
The script in post #1 should work with most modern shells such as ksh or bash and the Posix shells.
The error message comes from Bourne Shell which does not support the $( ) notation.

What Operating System and version are you running?
Code:
uname -a

What Shell are you using?
Code:
echo $SHELL

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

Sqlldr call via shell script prompts error

Good morning, I'm attempting to call sqlldr via shell script and it is prompting endIf is unec #!/bin/sh cd /tmp/v_tst FILENAME_WANTED=`date +"HourlyData_%Y%m%d_%H00.txt"` echo "FILENAME_WANTED = ${FILENAME_WANTED}" LIST_OF_FILES=`ls -rt HourlyData*.txt |tail -1` LIST_OF_FILES=`basename... (4 Replies)
Discussion started by: V1l1h1
4 Replies

3. Shell Programming and Scripting

awk script to call another script based on second column entry

Hi I have a text file (Input.txt) with two column entries separated by tab as given below: aaa str1 bbb str2 cccccc str3 dddd str4 eee str3 ssss str2 sdf str3 hhh str1 fff str2 ccc str3 ..... ..... ..... (1 Reply)
Discussion started by: my_Perl
1 Replies

4. Shell Programming and Scripting

Error executing date script

Hi, Seen below is a simple date script. #! /bin/ksh VL = `date +%m/%d` VL1 = `TZ=GMT+24 date +%m/%d` VL2 = `TZ=GMT+48 date +%m/%d` VL3 = `TZ=GMT+72 date +%m/%d` VL4 = `TZ=GMT+96 date +%m/%d` VL5 = `TZ=GMT+120 date +%m/%d` echo $VL echo $VL1 echo $VL2 echo $VL3 echo $VL4 echo... (2 Replies)
Discussion started by: jayadanabalan
2 Replies

5. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

6. Shell Programming and Scripting

Shell script to call Oracle archive backup script when file system reaches threshold value

Hello All, I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60% Need to identify the unique file system that reaches threshold value. ex: capacity ... (4 Replies)
Discussion started by: sasikanthdba
4 Replies

7. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

8. Shell Programming and Scripting

error when call function in bash script

Dear all, Could you please advice as I when call function i found the following error " refills: command not found" note that refills is function name. following also the function and how i call it function refills { echo "formatting refills and telepin" >> $log awk -F,... (20 Replies)
Discussion started by: ahmed.gad
20 Replies

9. Shell Programming and Scripting

how to run script? call other script? su to another user? make a cron?

Good morning. I am searching for "how-to"'s for some particular questions: 1. How to write a script in HP-UX 11. 2. How to schedule a script. 3. How to "call" scripts from the original script. 4. How to su to another user from within a script. This is the basics of what the... (15 Replies)
Discussion started by: instant000
15 Replies

10. Shell Programming and Scripting

call shell script from perl cgi script problem

hi,, i have perl scipt with line : system('./try.sh $t $d $m'); in shell scipt try.sh i have the line: echo $1 its not printing value of $t that i hav passed..y is it so..i am running it from apache web server (2 Replies)
Discussion started by: raksha.s
2 Replies
Login or Register to Ask a Question