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
# 1  
Old 06-08-2010
Error Works in shell but not script UNIX

ok i have a very simple UNIX script
Code:
#!/bin/bash
TERM=ansi;export TERM
PFCMARK=25;export PFCMARK
umask 0000
PFUMASK=000;export PFUMASK

#run for filepro menus and exectuables
echo "###########File Modification Log.############\r" > "/public/appl-fp$(date +%m-%d-%Y).txt"
find /appl/fp/ -mtime -1 -exec ls -l {} >> "/public/appl-fp$(date +%m-%d-%Y).txt"

now the script runs all the way through using sh script, but it names the file litterly as "appl-fp$(date +%m-%d-%Y).txt"
now if i run those same commands from the shell, it names the file correctly as "appl-fp06-08-2010.txt"

has anyone ran into this, or can anyone tell me why it is freaking out and not running the same way in the script as it does in the shell?

Last edited by Scott; 06-09-2010 at 02:57 AM.. Reason: Please use code tags
# 2  
Old 06-09-2010
Quote:
Originally Posted by dunpealslyr
can anyone tell me why it is freaking out and not running the same way in the script as it does in the shell?
In short, sh does not equal bash (even though /bin/sh might point to /bin/bash), or, as man bash states:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well.

Quote:
Originally Posted by dunpealslyr
Code:
echo "###########File Modification Log.############\r" > "/public/appl-fp$(date +%m-%d-%Y).txt"
find /appl/fp/ -mtime -1 -exec ls -l {} >> "/public/appl-fp$(date +%m-%d-%Y).txt"

However, what happens if you skip some of the quotes, e.g.:

Code:
FILE=/public/appl-fp$(date +%m-%d-%Y).txt
echo "###########File Modification Log.############\r" > $FILE
find /appl/fp/ -mtime -1 -exec ls -l {} >> $FILE


Last edited by dr.house; 06-09-2010 at 04:23 AM.. Reason: Quote & link added
# 3  
Old 06-09-2010
I actually tried changing the beginning different ways and it does nothing to help...
#!/bin/sh
or
#!/bin/bash
#!/bin/sh
or
#!/bin/sh
#!/bin/bash

its funny because i run all kinds of date backup scripts in linux and it is just fine with those commands. my first attempt actually was as you suggested with the path stored in a variable, it just comes up with this error message stating that it cannot find the variable!

i am just getting familiar with the unix machine, but small things like this are driving me nuts. (specially since vim points to vi, it took me a few minutes to figure that out...)

is there any other reasons this would be occuring? i would think it should *just* work...

---------- Post updated at 11:56 AM ---------- Previous update was at 11:33 AM ----------

I just copied and pasted your code exactly into my script and it says:

syntax error at line 4: `FILE=/public/appl-fp$' unexpected

the script files really dont like the dollar sign.
# 4  
Old 06-09-2010
Having two #! lines is useless. Only the first #! does anything.

Is your text editor perhaps putting in linebreaks?

Last edited by Corona688; 06-09-2010 at 02:01 PM..
# 5  
Old 06-09-2010
Quote:
Originally Posted by dunpealslyr
Code:
syntax error at line 4: `FILE=/public/appl-fp$' unexpected

Merely a gut feeling - but why not try a different text editor, e.g. Nano or Kate ...?
# 6  
Old 06-09-2010
tried your suggestion. nothing changed. i even echo'd the env variables in my script to make sure the correct directories are assigned. i am completely stumped at why its doing this...
# 7  
Old 06-09-2010
copy-paste the output of 'cat my-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