Works in shell but not script UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Works in shell but not script UNIX
# 8  
Old 06-09-2010
Figured out what was up, when switching over to unix, i didn't realize that `date` is used instead of $(date) in the script file.

can anyone maybe offer more insight to why the difference in the command when running in shell versus running in script?

---------- Post updated at 01:38 PM ---------- Previous update was at 01:35 PM ----------

btw, i am running sco unix. and a super outdated version at that. so anyone reading this, keep that in mind.
# 9  
Old 06-09-2010
[comment removed]

Last edited by dr.house; 06-10-2010 at 03:19 AM.. Reason: garbage collected (sorry ...)
# 10  
Old 06-09-2010
Quote:
Originally Posted by dunpealslyr
Figured out what was up, when switching over to unix, i didn't realize that `date` is used instead of $(date) in the script file.
switching over to unix from what?

$(date) should work in most anything but fabulously obsolete shells.
Quote:
btw, i am running sco unix. and a super outdated version at that. so anyone reading this, keep that in mind.
Well then.
# 11  
Old 06-09-2010
i am the systems administrator, so i am dealing with lots of o.s. including but not limited to:
SCO UNIX 'a few of them
UBUNTU 6.06(server), 9.04 (server, desktop), 9.10 (desktop) 'many
Windows xp (pro, home) / 7

i have personally used, ubuntu, redhat, suse, and many versions of live cd's for school and personally use.
i dont wish to print out the full paths and code i currently have now, plus its already over 100 lines of code. i will just make a quick script that show the difference, maybe someone here can give me insight onto why one would work and not the other. (i will provide the output of each)

contents of delme1
Quote:
#!/bin/bash

touch "/public/david/delme1$(date +%Y).txt"
FILE1="/public/david/delme1$(date +%Y).txt"
echo "OUTPUT" > $FILE1
File Name
Quote:
delme1$(date +%Y).txt
Content of file
Quote:
OUTPUT
contents of delme2
Quote:
#!/bin/bash

touch "/public/david/delme1`date +%Y`.txt"
FILE1="/public/david/delme1`date +%Y`.txt"
echo "OUTPUT" > $FILE1
File Name
Quote:
delme12010.txt
Content of file
Quote:
OUTPUT
It sound like you guys know a lot about unix and that this should not be happening. can you think of any reason why sco unix would freak out on such a simple syntax difference?
Remember, i can run the commands that fail with the script in the sco unix shell just fine.

the commands i used to run the scripts is this
sh delme1
sh delme2

i would really really really like to know what in the world the difference is!

Quote:
P.S. I tried changing line 1 from bash to sh as well, nothing changed in either script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Shell script not working but command works in command prompt

Hi everyone I have a problem with my script If I try directly this command /usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz It works But if I simply add this command in a script and... (8 Replies)
Discussion started by: picemma
8 Replies

4. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

5. Shell Programming and Scripting

variable assigment not works in shell script

Hi, The following assigment is not working within shell script but is working from command line. Could anybody advise why? OS - solaris 8 APPL=`grep "$Application" ldapapps |awk '{print $1}'` echo $APPL (5 Replies)
Discussion started by: urello
5 Replies

6. Shell Programming and Scripting

help with shell script: cp command not working, but mv command works...

Hello. I would like to ask your help regarding the cp command. We are using a cp command to create a back-up copy of our file but to no avail. It's just not working. We already checked the file and directory permissions and all seems correct. We have a script (ftp.script) which calls on... (1 Reply)
Discussion started by: udelalv
1 Replies

7. Shell Programming and Scripting

how the typeset command works in shell script

typeset -l section section=${2:-.} what does these 2 lines meaning? (1 Reply)
Discussion started by: venkatababu
1 Replies

8. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

9. Shell Programming and Scripting

Issue with script in linux but in unix works

I have this simple script: #! /usr/bin/sh #***************************************************************************** # *** get_input (question variable) *** #***************************************************************************** get_input () { echo "${BOLD}${1} : " read... (14 Replies)
Discussion started by: C|KiLLeR|S
14 Replies

10. Shell Programming and Scripting

Execution issue with shell script - works in a different environment

Hi I get the following error while executing the shell script. I did not get an error when I ran the script in a different environment (unix server). str-token.ksh: 0403-057 Syntax error at line 20 : `(' is not expected. This is the line which gives error string=(${pos_array}) Please find... (3 Replies)
Discussion started by: hidnana
3 Replies
Login or Register to Ask a Question