How to use a Shell Script for specific commands


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to use a Shell Script for specific commands
# 1  
Old 10-01-2009
How to use a Shell Script for specific commands

I have a set of commands that I am using to copy specific areas of source code in a Cold Fusion document and export the code into recreations of the original files into a sub-directory. Here are the 3 commands I am using:

Code:
mkdir ./out && for x in *.cfm; do awk '{FS="<!-- InstanceBeginEditable name=\ "title\" -->";
  RS="<!-- InstanceEndEditable -->"; print "<!-- InstanceBeginEdit able name=\"title\" -->" $2  "<!-- InstanceEndEditable -->"}' $x > ./out/$x; done

for x in *.cfm; do awk '{FS="<!-- InstanceBeginEditable name=\"content\" -->" ; RS="<!-- InstanceEndEditable -->";
 print "<!-- InstanceBeginEditable name=\"c ontent\" -->" $2  "<!-- InstanceEndEditable -->"}' $x >> ./out/$x; done

for x in *.cfm; do sed -i -e 's/<!-- InstanceBeginEditable name="title" -->ht ml<!-- InstanceEndEditable -->//'
 -e 's/<!-- InstanceBeginEditable name="title"  --><!-- InstanceEndEditable -->//' -e 's/<!-- InstanceBeginEditable name="cont ent" --><!-- InstanceEndEditable -->//'
 -e 's/<!-- InstanceBeginEditable name=" content" -->html<!-- InstanceEndEditable -->//' ./out/$x; done

The first command is making the sub-directory. It is also printing the area of code I want that is in between the two comment tags and exporting it into the same file name that the extraction was done, only into that sub-directory.

The second command is doing the exact same thing as the first command (minus the make directory command), except this one is aimed for a second comment phrase.

The third command is to delete unnecessary comment strings that would appear after using the first two commands.

I am very illiterate when it comes to this type of stuff. How I have gotten this far is by help of a co-worker. I understand the commands listed above, but that is basically all I know (exceptions are basic commands like pwd, ls, echo, etc.). I am using Cygwin on Windows XP Pro.

Now to the point of things. I want to be able to put these commands in a shell script so I do not have to keep typing them in every for every single web directory that I will use these commands on. Is there any simple way to do this? And can I use Notepad++ to create/edit the shell script?

-Dratech09
# 2  
Old 10-01-2009
Hi.

Just for you, I've downloaded and installed Cygwin!

I've been using it for about three minutes, and it's driving me up the wall already!

Copy your code into an editor (preferably not notepad!) and save it somewhere. If you use the script often, then /usr/bin, why not?

(let's assume notepad!)
Code:
cd /usr/bin
notepad cfCopy

Paste your code, save and exit.

Now, Notepad, being clever, will call your file cfCopy.txt, so...

Code:
mv cfCopy.txt cfCopy

Now you can "cd" to anywhere and run cfCopy.

If you chose to put the script somewhere else, not in your path (like /usr/bin), edit your bash profile:

Code:
cd
vi .bash_profile

and at the end, add the line:
Code:
PATH=/path_to_my_script:$PATH

"vi .bash_profile" doesn't work, as it seems cygwin doesn't come with vi (maybe it does, but I didn't have a good look yet). I would download WinVi and put it in /usr/bin! Like I just did. Then you'll never have to use notepad again.

Hope this helps!
# 3  
Old 10-02-2009
scottn, thank you for the reply!

I did as you said, but when I tried to run it I got the following error:

Code:
/usr/bin/cfm: line 4: syntax error: unexpected end of file

What do I seem to be doing wrong?

I also renamed the command file to cfm.sh and Im getting the exact same error.

-Dratech09
# 4  
Old 10-02-2009
Hi.

I had the exact same problem at first.

After installing cygwin I wrote a "hello world" equivalent script to test it:

Code:
ls

Which gave this error.

Then I fiddled with it adding blank lines at the end, etc.

But I eventually got it working (I've had colds that came and went quicker) by using WinVi (again with some fiddling).

I can't believe I'm the first person to write a script in Cygwin (I most certainly am not).

But I can say that what I wrote does work! I got it to work by "fiddling".....

Can anyone here from the Cygwin community - if there is such a thing - recommend something, anything, that means we can write a basic script without having to muck around for ages pampering to every of Windows' short-comings in relation to saving a basic text file to disk?!

Last edited by Scott; 10-02-2009 at 03:24 PM..
# 5  
Old 10-02-2009
scottn,

I am using Cygwin because my co-worker said to use it. Is there any other Unix command line interfaces for Windows that might work better than Cygwin?

-Dratech09
# 6  
Old 10-02-2009
From the scripting perspective, there's not a problem. For me the problem is from the Windows (DOS) side. We must be doing something wrong.

Just "fiddle" until a Cygwin guru turns up...

---------
I've just played around some more, and it seems that (in notepad) adding a blank line at the very end makes it work.

I will have to Wikipedia the origins of CRLF. For the life of me I can't see why both are neccessary. UNIX didn't have both for 40 years, and noone died!

Last edited by Scott; 10-02-2009 at 03:38 PM..
# 7  
Old 10-02-2009
Quote:
Originally Posted by scottn
I've just played around some more, and it seems that (in notepad) adding a blank line at the very end makes it work.
I have done that as well and I get the same exact error. Not sure what I am doing wrong.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Two exec commands in one shell script?

Hi Folks - Is there a way to add two execs to one script? For instance, I need to redirect the stdout and stderr to two separate directories. I want to do this: #::-- Direct STDOUT and STDERROR to repositories --::# exec 2>"${_ERRORFILE}" > "${_LOGFILE}" exec 2>"/new/path/file.err" >... (7 Replies)
Discussion started by: SIMMS7400
7 Replies

2. Shell Programming and Scripting

Script to run commands at a specific time.

Hello All, I have written a script which which is working fine to a certain logic of it. But i want a part of the script to run two commands at 00:10 hrs every day. These two command are 1. rm -rf /path/to/folder 2. mail the content of a file. How do i achieve this. Thanks. ... (4 Replies)
Discussion started by: Siddheshk
4 Replies

3. UNIX for Dummies Questions & Answers

Commands to run from shell script

Hi script> isumid 98765432 if i give above command in cmd prompt it is running the same thing if i give inside the shell script it is not working below is the code #!/bin/bash isumid 98765432 please give me a solution (16 Replies)
Discussion started by: Ramrangasamy
16 Replies

4. Shell Programming and Scripting

Linux commands in shell script?

I am trying to learn to write basic shell scripts. I have a little experience with perl but none with shell. I am trying to write a simple script to write the last 15 or so lines of log files for my web server to a temp file so I can view all at once. Here's what I have. Are you not able to use... (6 Replies)
Discussion started by: ktb231
6 Replies

5. Shell Programming and Scripting

Using Ex editor commands in a shell script - Help!

Hi all, I am trying to use the Ex editor and its commands in a script - more specifically within an if statement within a while loop. Here are the basics of the loop: cat $file1 | while read line do grep $line $file2 if ] then echo $line > $file2 elseex $file2 /ESI185... (4 Replies)
Discussion started by: luke222010
4 Replies

6. Shell Programming and Scripting

Why can't embed commands like fg or bg in a shell script ?

Hi Can someone explain in an easy way that why can't embed commands like fg or bg in a shell script ? (4 Replies)
Discussion started by: qiulang
4 Replies

7. Red Hat

how to write shell specific commands?

I am using Fedora 8,Red hat 9. Whenever we write a new command. Then we goto "/usr/bin" and then place this in this directory.And hence we can use it as a command anywhere from the terminal. We generally see commands like "trap" which run only in bash shell.We also have other shell specific... (1 Reply)
Discussion started by: nsharath
1 Replies

8. Shell Programming and Scripting

How to get ascii value using shell commands/script

Hi gurus, Need command/code to get the ASCII value for a character say 65 for A and vice versa in shell script. Thanks in advance (2 Replies)
Discussion started by: kittu1979
2 Replies

9. Shell Programming and Scripting

shell script to run a few commands help!

Hi friends this is first post i am very new to shell scripting so i require your expertise to do the following thank u I need to write a shell script which will run the following commands pg_dump bank > backup(Enter) Wait for bash prompt to appear coz it indicates that the command is... (23 Replies)
Discussion started by: perk_bud
23 Replies

10. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question