LinuxQuestions.org
Help answer threads with 0 replies.
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 04-10-2008, 11:34 AM   #1
no.4
LQ Newbie
 
Registered: Sep 2006
Distribution: Debian 4.1
Posts: 16

Rep: Reputation: 0
converting text file to a cmd file


I realize I should know this. What do I do next when I have created a text file called ngstart.cmd which has the following command in it: sudo /etc/init.d/nagios start. It seems I recall you have to do something with the file to make it execute when it is typed in at the prompt.

Thanks in advance,
Marty
 
Old 04-10-2008, 11:41 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
In order to be executed a file should have the executable bit set, at least for the file owner, like this
Code:
-rwxr--r-- 1 colucix users 170345 Apr 10 18:25 ngstart.cmd
Then you can put your script in a directory which is in your PATH. In this way you can run it typing its name only. Otherwise you have to type its relative or absolute path, as in:
Code:
./ngstart.cmd
../../some/dir/ngstart.cmd
/home/colucix/ngstart.cmd
 
Old 04-10-2008, 11:42 AM   #3
dkm999
Member
 
Registered: Nov 2006
Location: Seattle, WA
Distribution: Fedora
Posts: 407

Rep: Reputation: 35
You are correct; you should know this, but since command lines in all flavors of UN*X are best described as "wild conventions flying in loose formation", your memory lapse is hereby absolved:
Code:
 #chmod ug+x ngstart.cmd
 
Old 04-10-2008, 11:45 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

You can execute the file by doing the following:

sh file

Or parse the file by doing:

. file

If you want to make it an actual shell script, add a hash-bang and give it the proper execution rights:

Add a hash-bang: #!/bin/bash Should be the first line of the script/file.
Change permissions: chmod 750 file

You can now execute it as follows:

./file

If the directory that the file is in is part of your PATH, you don't even need the ./

Hope this clears things up.
 
  


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 parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
converting into file.tar.gz file ? kapsikum General 2 03-21-2005 12:33 AM
converting text file from linux to ms dos Berhanie Linux - Newbie 4 12-24-2003 10:54 PM
renaming or converting a text file to a dat file... tangaz Linux - Software 1 10-24-2003 06:57 AM
CSH: "cmd >& file" or "cmd </dev/null >& file" stefanlasiewski Programming 1 09-08-2003 04:19 PM

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

All times are GMT -5. The time now is 02:38 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