LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 08-11-2011, 08:59 AM   #1
Juanmadrid
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Rep: Reputation: Disabled
Please help! simple bash script


is these oke?

#! / Bin / bash
cp /tmp/programming/practise/*.jpg /tmp/programming/practise/*music* /tmp/programming/Juan

I want tomake a script which copy 2 types of files from one directory to another! Thank you for your time!
 
Old 08-11-2011, 09:10 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by Juanmadrid View Post
is these oke?

#! / Bin / bash
cp /tmp/programming/practise/*.jpg /tmp/programming/practise/*music* /tmp/programming/Juan

I want tomake a script which copy 2 types of files from one directory to another! Thank you for your time!
Hello, and welcome to LQ!

At first, please use code-tags when posting code.

I found only one error in your script, this line:
Code:
#! / Bin / bash
This should be
Code:
#! /bin/bash
Linux is case-sensitive, unlike Windows Bin and bin are not the same. Since this is the path to the interpreter for that script it may not contain spaces that are not in the path, and if there are spaces in the path they have to be escaped.
 
Old 08-11-2011, 09:20 AM   #3
Juanmadrid
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you for your fast response!
so script is oke when that error is corrected?

Last edited by Juanmadrid; 08-11-2011 at 09:21 AM.
 
Old 08-11-2011, 09:27 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Should be. What happens when you try it?
 
Old 08-11-2011, 09:37 AM   #5
Juanmadrid
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
should I remove / on beginning of location so it should be tmp/programming/practise/*.jpg
 
Old 08-11-2011, 09:44 AM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Paths beginning with / are absolute paths, paths without leading / are relative paths. A relative pathe will every time be interpreted from the current working directory, while the absolute path will always be interpretted from the root directory (/).
That means, if you don't use the leading / and your current directory doesn't contain a tmp/programming/ directory your script will not work.

For a better understanding of paths in Linux you may want to read this.

Last edited by TobiSGD; 08-11-2011 at 09:45 AM.
 
Old 08-11-2011, 09:44 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Depends ... is the path to where the files are under /tmp or the tmp directory where you launch the script?
 
Old 08-11-2011, 09:56 AM   #8
Juanmadrid
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
oh nice explanations thank you!
 
  


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
Simple bash script please help! Cheloo Linux - General 3 07-13-2008 03:54 PM
Simple Bash Script sachinh Linux - General 5 05-23-2007 09:54 PM
Simple bash script help zok Linux - General 4 12-15-2006 11:56 AM
Need simple bash script help rickenbacherus Linux - General 1 11-01-2006 02:44 AM
Simple Bash Script Help njdownes Programming 2 03-05-2005 07:35 AM

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

All times are GMT -5. The time now is 01:35 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
Open Source Consulting | Domain Registration