script not working


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers script not working
# 1  
Old 01-20-2010
Error script not working

hi guys im new to unix and what to get this script working
the scripts purpose its purpose is to move files
i copy it from a HP UX pdf just for practice but
when i execute it comes up wit this error command not found
on the line if[ $# -eq 0 ] plz help me and thank in advance
to those who do ps im using the bash shell
Smilie
Code:
#############################################################
# This shell program will prompt the user for moving files. #
#############################################################
#(1) test if there are any arguments
if [ $# -eq 0 ]
 then
  echo "No arguments: include file name."
  exit
fi
#(2) ask if file is to be moved to directory or file
 echo "Move to directory or new file name (d or f)?\c"
 read x
#(3) test if x is a directory; if not, leave script
if [ ${x:?} = d ]
then
 echo "Enter directory name ->\c"
 read dir1
# perform the move
 mv $1 $dir1
 echo "$1 moved to $dir1"
exit
#(4) test if it is a file
elif [ $x = f ]
 then
  echo "Enter new file name ->\c"
exit
#(5) response is not d or f
else
 echo "$x not a correct response."
 exit
fi

# 2  
Old 01-20-2010
The script as posted has no obvious syntax errors and we would expect it to run in bash.

The line you quote:
Quote:
if[ $# -eq 0 ]
is not the same as in the full script. There should be a space character after "if".
Please check that the script copied ok and displays correctly with "more scriptname".
# 3  
Old 01-20-2010
cheers i give it a try Smilie

---------- Post updated at 09:38 AM ---------- Previous update was at 09:32 AM ----------

OMG i cant belive that was it a space
is all i need thank again methyl

---------- Post updated at 10:15 AM ---------- Previous update was at 09:38 AM ----------

oh now getting this other error it wont let
move the file to the new directory when i
reach the thrid option it tell me to enter
the directory name i enter it (~/cPlusPlusPractice/pointers)
and the error missing destination file operand after 'thisFile.txt' come
up what im i doing wrong
# 4  
Old 01-22-2010
solved

ohhhhh yeahhhhhaaaa
figure it out need to use a variable
eg dir2=~/directory u what it to go 2.
then when the script prompts you u
feed it $dir2 make sure the $ is before
the variable name or else it wont work.
SmilieSmilie

---------- Post updated at 10:26 PM ---------- Previous update was at 10:24 PM ----------

ohhhhh yeahhhhhaaaa
figure it out need to use a variable
eg dir2=~/directory u want the file to go into 2.
then when the script prompts you u
feed it $dir2 make sure the $ is before
the variable name or else it wont work.
SmilieSmilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with speeding up my working script to take less time - how to use more CPU usage for a script

Hello experts, we have input files with 700K lines each (one generated for every hour). and we need to convert them as below and move them to another directory once. Sample INPUT:- # cat test1 1559205600000,8474,NormalizedPortInfo,PctDiscards,0.0,Interface,BG-CTA-AX1.test.com,Vl111... (7 Replies)
Discussion started by: prvnrk
7 Replies

2. UNIX for Beginners Questions & Answers

Why is this script not working?

for file in $(find /home/p611568/*.rpt -mtime -2 | grep -v ftplog) do awk '$1 == "XifPages," {PAGE = $5} $1 == "XifEndOfDocuments," {LINE = $5} index($0,"Value") && index($1,"Info") {sevGTI = 1} END {if (sevGTI) printf "%7s%10s%s",PAGE,LINE ... (4 Replies)
Discussion started by: bcarosi
4 Replies

3. Shell Programming and Scripting

Script not working

Hi i have write the one scripts and the scripts is error. The scripts purpose select one directory to check the file is there or not. i will give the two format of file to search the mention the path one file is there to select the file one copy the another location.please check the my script give... (1 Reply)
Discussion started by: rajivgandhi
1 Replies

4. UNIX for Dummies Questions & Answers

My script is not working

Hi All, I am trying to calculate the total_amount based on two key fields. Here is the script. I am new to unix. So please help me to find out the error in this script. I'm getting error like "command not found" and ]; is missing.. PRE_LBNO=0 PRE_DATE=0 TOT_PAY=0 for line in `cat... (4 Replies)
Discussion started by: lathanandhini
4 Replies

5. Shell Programming and Scripting

expect script inside shell script not working.

Shell Scipt: temp.sh su - <$username> expect pass.exp Expect script: pass.exp #!/usr/bin/expect -f # Login ####################### expect "Password: " send "<$password>\r" it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Discussion started by: bhavesh.sapra
2 Replies

6. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

7. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

8. Shell Programming and Scripting

HELP !! script not working..

Hi all, I have a piece of code which cork perfect. It copy the no of lines from some files (*.log) into finalLog file. It read the lines after the line have text "ntot". Here it is : #!/bin/bash ... (10 Replies)
Discussion started by: nrjrasaxena
10 Replies

9. Shell Programming and Scripting

Perl script 'system' linking to local shell script not working

Trying to figure out why this works: printpwd.pl #!/usr/bin/perl use CGI::Carp qw( fatalsToBrowser ); print "Content-type: text/html\n\n"; $A = system("pwd"); $A = `pwd`; print "$A\n"; ^^actually that works/breaks if that makes any sense.. i get the working directory twice but when... (5 Replies)
Discussion started by: phpfreak
5 Replies

10. Shell Programming and Scripting

Script not working..."sort" not working properly....

Hello all, I have a file - 12.txt cat 12.txt =============================================== Number of executions = 2 Total execution time (sec.ms) = 0.009883 Number of executions = 8 Total execution time (sec.ms) = 0.001270 Number of... (23 Replies)
Discussion started by: Rahulpict
23 Replies
Login or Register to Ask a Question