LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices

Reply
 
Search this Thread
Old 03-31-2006, 12:58 PM   #1
$Linuxnoob
Member
 
Registered: Mar 2006
Location: Ypsilanti, Michigan
Distribution: Fedora core 5 Ubuntu 6 Slackware 11(if and when I get it running)
Posts: 151

Rep: Reputation: 30
Bash shell scripting question.


when I'm attempting to write my own shell script after I've written it where should I save it to to be executable?

Also is the scarlar sign the one you use to execute?


$script.sh

and .sh for bash is the correct ending yes?
 
Old 03-31-2006, 01:04 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
all of your questions are actually illogical or irrelevant, if i'm understanding the 2nd one right in the first place...

1) you can put a script *anywhere* there is no special location.

2) you mean the $ sign? no, that is just an example command prompt. it is used in code to clarify exactly how to run a program.

3) this is not windows, files are recognized by what they actaully are, not what characters just so happen to be on the end of it. the use of .sh is a handy visual convention, but absolutely non essential

i guess you're just asking how to make a script exectuable? run "chmod +x scriptname" and then you canjust run the script as if it were a binary executable.
 
Old 03-31-2006, 01:05 PM   #3
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 327Reputation: 327Reputation: 327Reputation: 327
The location and name of the file are not important. The location is usually in a bin directory. On your userid, in ~/bin/ which should be in your default PATH:

echo $PATH

The file extension is not used on Linux, it's is strictly for your information. The executable could be called 'linuxnoob.sh', 'linuxnoob.xyz' or just 'linuxnoob' - it doesn't make any difference.

To make a shell script executable, two things are needed:

1. The script must start with #! followed by the full path to the shell interpreter. For example:

#!/bin/bash

2. The executable flag must be set on the file. For example:

chmod 755 somescript
 
Old 03-31-2006, 03:43 PM   #4
$Linuxnoob
Member
 
Registered: Mar 2006
Location: Ypsilanti, Michigan
Distribution: Fedora core 5 Ubuntu 6 Slackware 11(if and when I get it running)
Posts: 151

Original Poster
Rep: Reputation: 30
How do you CHMOD a file to 755 through CLI?
 
Old 03-31-2006, 03:51 PM   #5
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 327Reputation: 327Reputation: 327Reputation: 327
Quote:
Originally Posted by $Linuxnoob
How do you CHMOD a file to 755 through CLI?
You open a terminal, and at the prompt issue the command:

chmod 755 filename

Replace 'filename' with the name of the file you want to chmod. The '755' means:

rwxr-xr-x

Which expands to:

Owner permissions: rwx (binary 111=7)
Group permissions: r-x (binary 101=5)
Others permissions: r-x (binary 101=5)

If you don't want others in your group or other users on the system to be able to access the file, then use 700 instead.

Last edited by macemoneta; 03-31-2006 at 03:52 PM.
 
Old 03-31-2006, 03:52 PM   #6
$Linuxnoob
Member
 
Registered: Mar 2006
Location: Ypsilanti, Michigan
Distribution: Fedora core 5 Ubuntu 6 Slackware 11(if and when I get it running)
Posts: 151

Original Poster
Rep: Reputation: 30
Thanks a lot. I tried to CHMOD before, but never had luck hehe, you've been a lot of help.
 
Old 03-31-2006, 03:53 PM   #7
$Linuxnoob
Member
 
Registered: Mar 2006
Location: Ypsilanti, Michigan
Distribution: Fedora core 5 Ubuntu 6 Slackware 11(if and when I get it running)
Posts: 151

Original Poster
Rep: Reputation: 30
[root@ip-181-157 ~]# chmod 755 script
chmod: cannot access `script': No such file or directory


I tried as you said, but it returned this, am I doing something wrong?
 
Old 03-31-2006, 03:55 PM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
well you've got to be in the right directory to reach the file... or use an absolute or relative file path e.g. /home/user/script or ../user/script etc...
 
Old 03-31-2006, 03:56 PM   #9
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 327Reputation: 327Reputation: 327Reputation: 327
If the file 'script' is not in the current directory, then you must either cd to the correct directory, or specify the path. For example, if 'script is in the '~/bin/' directory, you can either:

cd ~/bin
chmod 755 script

or

chmod 755 ~/bin/script
 
Old 03-31-2006, 03:59 PM   #10
$Linuxnoob
Member
 
Registered: Mar 2006
Location: Ypsilanti, Michigan
Distribution: Fedora core 5 Ubuntu 6 Slackware 11(if and when I get it running)
Posts: 151

Original Poster
Rep: Reputation: 30
Ah, excellent, now to stop the program from CLI you'd use something to the effect of kill ? or what would you use?
 
Old 03-31-2006, 04:09 PM   #11
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,151

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Are you running as "root"?

This should never be necessary unless you're making significant system changes. Or inviting strangers to use your system for anything they want to do.

Read man sudo and man sudoers to see how you can permit your "standard" login to execute privileged commands.

As to you problem, script must be the full path to the actual script name and location.
 
Old 03-31-2006, 04:45 PM   #12
$Linuxnoob
Member
 
Registered: Mar 2006
Location: Ypsilanti, Michigan
Distribution: Fedora core 5 Ubuntu 6 Slackware 11(if and when I get it running)
Posts: 151

Original Poster
Rep: Reputation: 30
Oh thanks for the help. I will read those and start using my other name.

If for instance i had someof my poetry on root in fileA and someof my school assignments in fileB is there anyway I can make those files viewable for other users, which consequently is me and myself hehe.
 
Old 04-01-2006, 07:55 AM   #13
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,151

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Sure. use the mv command and the chown command. For example:
Code:
$ sudo mv /root/<Poetry File> /home/<me>/<Poetry Directory>/
$ sudo chown <me>:<my group> /home/<me>/<Poetry Directory>/<Poetry File>
Where, of course, you need to replace everything in angle brackets (including the brackets) by the actual names you use.

See man mv and man chown for details.

Also, note that info --apropos <keywords> and man -K <keywords> will search the on-line documentation for any command whose description uses that keyword. (And, of course, info info and man man will give you details about the info and man commands.
 
Old 04-01-2006, 01:12 PM   #14
$Linuxnoob
Member
 
Registered: Mar 2006
Location: Ypsilanti, Michigan
Distribution: Fedora core 5 Ubuntu 6 Slackware 11(if and when I get it running)
Posts: 151

Original Poster
Rep: Reputation: 30
Thanks for the assistance.
 
  


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
shell (bash) scripting question(s) boxerboy Programming 5 11-08-2005 03:51 PM
Bash shell scripting question. pete1234 Programming 11 09-25-2005 02:59 AM
Bash shell scripting question. Itsu Linux - General 3 04-30-2005 03:52 AM
Bash shell scripting question mehesque Programming 2 07-15-2004 10:54 AM
BASH Shell Scripting Question xianzai Programming 5 03-19-2004 07:50 AM


All times are GMT -5. The time now is 02:10 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration