LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-17-2008, 07:10 AM   #1
zbe
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Rep: Reputation: 0
Can't execute Bash script.


Hello there,

I have a bash script with the following code in it:

Code:
#!/bin/bash
for url in 'cat $1'
do
 wget -c --load-cookies ~/.cookies/rapidshare $url
done
The code is in a file downloader.sh

I ran
Quote:
chmod +x downloader.sh
to make it executable, but whenever I try to run it by typing
Code:
/downloader.sh somefile
it tells me there is no such command or file.

Anyone know whats up?

Cheers,

Zlatan

P.S. I am trying to run the script for the same directory and I am using an Acer Aspire One with the default linux distro (if that holds any relevance).
 
Old 10-17-2008, 07:27 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Why the slash at the beginning of the command line? If you mean "run a command from the current directory" you have to put a dot and a slash. That is
Code:
./downloader.sh somefile
where the dot means the current working directory. Moreover, no need of a cat command in the for loop. If you want to loop over the arguments, better doing something like
Code:
for url in "$@"
do
  <commands here>
done
 
Old 10-17-2008, 07:36 AM   #3
zbe
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
"./" works thank you for that! Although I thought I had tried that :s.

the file I'm passing to my script is a list of urls, each on it's own line. 'cat $1' and '$@' aren't working for looping through them. Do you know what I could use?

I don't really know that I'm doing, I just copied the script from some website.

Thank you for your time,

Zlatan.
 
Old 10-17-2008, 07:54 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by zbe View Post
the file I'm passing to my script is a list of urls, each on it's own line.
Uh, sorry... I was thinking at somefile as the actual file to download.

Quote:
Originally Posted by zbe View Post
'cat $1' and '$@' aren't working for looping through them. Do you know what I could use?
You can try something like
Code:
#!/bin/bash
while read url
do
  echo "$url"
done < somefile
substitute the echo command with the actual wget command. This is just to check if the file is correctly read.

Just an advice: don't accept downloaded scripts "as is" without knowing what they really do. Nor accept suggestions (mine included) without verifying the presence of erroneous or malicious commands. A quick look at the man pages or at the Advanced Bash Scripting Guide should be enough to prevent (intentional or not intentional) damage to your system.
 
Old 10-17-2008, 08:05 AM   #5
zbe
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Excellent, thank you very much.

Thanks for the warning, I would usually spot something malicious (I'm a programmer, I'm just very new to linux/bash)
 
  


Reply



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
how to execute bash-script from .bashrc mrsvan Linux - General 3 07-21-2008 07:26 AM
Execute bash script inside PHP creatorrr Programming 11 11-21-2007 04:32 PM
remote execute a bash script vmware Linux - Enterprise 3 09-07-2006 03:01 PM
fastest way to execute another bash script ?? michael_util Programming 3 08-23-2004 10:04 AM
Trying to execute bash script upon login?? mr-d-2003 Linux - Newbie 4 10-30-2003 03:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:04 AM.

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
Open Source Consulting | Domain Registration