LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-21-2006, 04:21 PM   #1
en8scl
LQ Newbie
 
Registered: Oct 2003
Posts: 5

Rep: Reputation: 0
Question Creating a bash script which understands paths to files


Hi

I am new to linux and I am trying to create a script which will eventually be put in a cron job. However I'm not having much luck with any script at the mo (even this basic example as it can't find the files I'm referencing).

Even a simple cat command doesn't seem to work once in my script.

From the command line:

cat filename

work fines and displays the contents of the file to the screen

As soon as I create a test.sh script (which I have made executable) with the following lines it stops working:

#!/bin/bash
cat filename
echo hello world

and I get an output which says:

: No such file or directory
hello world

From this I assume it is running the script alright as it prints the 'hello world' part.

I have tried giving the full path to the file as well e.g.:

#!/bin/bash
cat /home/some/directory/filename
echo hello world

but it still can't find the file...

Where am I going wrong?

Please help me - its driving me nuts
 
Old 05-21-2006, 04:37 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
What is the actual output from the script? if your path starts with a / then it is absolute so will always work if other factors like file ownerships and permissions are not conflicting.
 
Old 05-21-2006, 04:47 PM   #3
en8scl
LQ Newbie
 
Registered: Oct 2003
Posts: 5

Original Poster
Rep: Reputation: 0
sh-3.00$ bash reset_demo_db.sh
: No such file or directoryweb/demo_reset/tsweb_zendemo.sql
Hello World
Wish this would work
sh-3.00$

is the exact copy from the console when the script has exactly this in it:

#!/bin/bash
cat /hsphere/local/home/tsweb/demo_reset/tsweb_zendemo.sql
echo Hello World
echo Wish this would work
 
Old 05-21-2006, 04:48 PM   #4
en8scl
LQ Newbie
 
Registered: Oct 2003
Posts: 5

Original Poster
Rep: Reputation: 0
and I am logged in as the owner of both the script and sql file
 
Old 05-21-2006, 05:05 PM   #5
ethics
Senior Member
 
Registered: Apr 2005
Location: London
Distribution: Arch - Latest
Posts: 1,522

Rep: Reputation: 45
It is all case sensitive so make sure that is ok, and that the path is correct
 
Old 05-21-2006, 05:06 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
ok, so what does
Code:
ls -l /hsphere/local/home/tsweb/demo_reset/tsweb_zendemo.sql
say?
 
Old 05-21-2006, 05:11 PM   #7
en8scl
LQ Newbie
 
Registered: Oct 2003
Posts: 5

Original Poster
Rep: Reputation: 0
[root@cp demo_reset]# ls -l /hsphere/local/home/tsweb/demo_reset/tsweb_zendemo.sql
-rw-r--r-- 1 tsweb tsweb 586027 May 17 22:49 /hsphere/local/home/tsweb/demo_reset/tsweb_zendemo.sql
 
Old 05-21-2006, 05:28 PM   #8
bc8o8
Member
 
Registered: Jun 2003
Location: Boston, MA
Distribution: Debian
Posts: 57

Rep: Reputation: 15
This error:
Quote:
Originally Posted by en8scl
: No such file or directoryweb/demo_reset/tsweb_zendemo.sql
doesn't seem to match this line
Quote:
Originally Posted by en8scl
cat /hsphere/local/home/tsweb/demo_reset/tsweb_zendemo.sql
If that error was for that line (as displayed) it would read:
cat: /hsphere/local/home/tsweb/demo_reset/tsweb_zendemo.sql: No such file or directory

I'm wondering if there are some unprintable garbage characters that are causing weird problems. I would try deleting the whole line and retyping it. I know it sounds stupid -- but I've had similar issues that where solved by retyping.

Last edited by bc8o8; 05-21-2006 at 05:31 PM.
 
Old 05-21-2006, 05:42 PM   #9
en8scl
LQ Newbie
 
Registered: Oct 2003
Posts: 5

Original Poster
Rep: Reputation: 0
Thankyou so much bc8o8

You were right - started a completely new file and it worked fine - weird. How do I avoid that in the future?
 
Old 05-21-2006, 08:22 PM   #10
bc8o8
Member
 
Registered: Jun 2003
Location: Boston, MA
Distribution: Debian
Posts: 57

Rep: Reputation: 15
What text editor were you using? I don't think I've seen the problem in Vim or Emacs, but I could be wrong. Typically it happens in lower quality editors when keystrokes are hit that don't have a printable ASCII equivalent. It's sort of like when you're in a terminal and you start seeing characters like ^[A -- except the editor doesn't know how to handle them. The best way to avoid them is to not hit those keystrokes a more realistic solution is to use a better editor just in case you do accidentally type them.

Glad I could help!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem creating BASH script with files that have whitespace scattaneo Linux - General 2 11-06-2004 06:40 PM
Bash script to do copying and ISO image creating, etc. satimis Programming 2 09-19-2004 10:47 PM
Creating switches in a bash script Moto_Jon Programming 2 07-28-2004 07:06 PM
Help creating a Bash script gothicreader Linux - Newbie 4 10-10-2003 02:36 PM
need help creating a bash script zibertron Linux - General 3 01-31-2003 10:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration