Line works in solo but not in program?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Line works in solo but not in program?
# 1  
Old 08-20-2006
Line works in solo but not in program?

Now I am just getting frustrated and confused... if anyone has some advice on how this anomoly is occurring I would greatly appreciate it.

Code:
cat helpme.txt | awk 'NR<5{printf("%-20s %-20d %-20d %-20.1f\n","hello",$1,$2,$3)}' | sort -rk4

This line works fine in solo - reads the three fields from helpme.txt and adds a first field "hello" before the others on output... seems simple enough and it works fine on its own on the command line.

In a small program it doesn't work...

Code:
#!/bin/sh

echo "Please enter the file you want compressed: \c"; read filename 

echo File: $filename

# check to see file exists and is readable with -r
if [ -r $filename ]
then

echo gzip | gzip -f $filename; gunzip -l $filename.gz > $filename.txt; gunzip $filename
gzip -f rose.bmp; gunzip -l rose.bmp.gz >> $filename.txt; gunzip rose.bmp.gz

cat helpme.txt | awk 'NR<5{printf("%-20s %-20d %-20d %-20.1f\n","hello",$1,$2,$3)}' | sort -rk4

else

echo sorry the file does not exist or is not readable

fi

So at this point I am thinking magic?

And yes with only the three fields in the short program it does work fine.
# 2  
Old 08-21-2006
What is your default shell? When you are running command interactively? I think that might be a problem, because with this
Code:
#!/bin/sh

you are telling kernel to use sh to process your code and maybe your default shell is different
Code:
echo $0

might help you.

Regards,
Tayyab
# 3  
Old 08-21-2006
The default is csh and the program runs sh - c shell and bourne shell

I'm beginning to wonder if I've somehow done something to my shell - one can change shell behaviour? Its just I use vpn to access the uni UNIX account and today I saw the same code operate correctly on the same UNIX environment while not in my account.

Does this make sense to anyone?
# 4  
Old 08-21-2006
You mean same code doesn't work when you come thru VPN with same account, and it works with same account when you are directly connected to your network?

If code works with one account and doesn't work with other account, check login files for your csh, good luck.
# 5  
Old 08-21-2006
sorry i meant the code works on the sys admin computer on the same unix system at the uni... but isn't working on my account.

I think I need to get them to set up a new account for me which works correctly. Thanks for the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script Works But Need It to Exit Upon Closing Program

Running Xubuntu 16.04 with shell version "GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)," I have a working script that consistently renames a Chrome window: #!/bin/sh while sleep 1; do xdotool search --name chrome 2>/dev/null | while read id; do xdotool set_window --name... (21 Replies)
Discussion started by: jakefish
21 Replies

2. Shell Programming and Scripting

Need to understand how the line in perl program works as shell commend

I have a file with two line, one is header, the other actual value: TYPCD|ETID2|ETID|LEG ID|PTYP|PTYP SUB|TRD STATUS|CXL REASON|CACT|CACTNM|ENCD|ENC D NM|TRDR|ASDT|TRDT|MTDT|STDT|LS|SECID|SECID TYP|SECNM|PAR|STCC|MARKET PRICE|DIS MARKET PRICE|MARKET PRICE CURRENCY|SRC OF SETTLEMENT... (2 Replies)
Discussion started by: digioleg54
2 Replies

3. Shell Programming and Scripting

Works on command line but not in script

OSX 10.9 I am building a script that evaluates the difference between 2 files. Here is a command that does not work transparently. Running this command in Terminal yields great results; however when I put that line in a .sh script, I get the errors shown below. Am I doing something silly? ... (1 Reply)
Discussion started by: sudo
1 Replies

4. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

5. UNIX for Dummies Questions & Answers

C-program works fine interactively, but not on the SGE server

Greetings, I have a C-program that is made to implement a hidden Markov model on an input file. The program is very memory intensive. I've installed it on my local server where I have an account and it compiles fine. The way they have the server set up is that you can either work... (1 Reply)
Discussion started by: Twinklefingers
1 Replies

6. Windows & DOS: Issues & Discussions

Command works on CMD line but not in batch?

Hi All, This command works when I type it on but when I run the batch file it doesn't..any ideas why? attrib.exe * | find /c /v "" >filecount.txt (1 Reply)
Discussion started by: Grueben
1 Replies

7. UNIX for Dummies Questions & Answers

Works on command line but not in script

Hey guys. Hopefully this is an easy one but having reference similar problems on the web I still can't fix it. I am doing a recursive find and replace from a script. Of course I could just run the damn thing from the command line but it's bugging me now and want to get it working. grep -rl... (4 Replies)
Discussion started by: anthonyjstewart
4 Replies

8. Shell Programming and Scripting

s3cmd works on command line not on cron

Ubuntu 9.10 is my linux distro Based on forums they say that the problem is with environment . here is my case: login as user, then sudo -s using this command: s3cmd put file s3://bucket >>worked! now here is the simple script intended for testing: #! /bin/bash env >/tmp/cronjob.log... (1 Reply)
Discussion started by: qwerty20
1 Replies

9. Solaris

Graphical program no longer works after Solaris 10 upgrade

This is a fairly complex issue. I do not have a lot of knowledge on X11. But here are the things. I am running a program called Synergy off a Solaris server. The server sits in a remote network and can be accessed via NAT. Using Putty, I will enable X11 forwarding and launch Synergy via Putty.... (0 Replies)
Discussion started by: Leion
0 Replies

10. Shell Programming and Scripting

works from cmd-line but not in script

hi I'm trying to query a directory, check it's the right directory, return the results into a text file, put text file into an array and navigate the subdirectories and delete contents. find `pwd` -type d | grep TESTINGDIR > dirList.txt The txt file is created from the cmd-line but not in... (4 Replies)
Discussion started by: OFFSIHR
4 Replies
Login or Register to Ask a Question