LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-10-2006, 12:56 PM   #1
DJOtaku
Member
 
Registered: Oct 2004
Location: USA
Distribution: Fedora 20; Arch; Kubuntu; Debian
Posts: 710

Rep: Reputation: 31
converting bash script to csh


Trust me, I don't want to do this, but we're stuck with an very important legacy system which has csh, but not bash. How can I convert the following to csh?

#!/bin/bash
# need to change above to /bin/csh

#parse files to allow a command that normally only takes one file as an argument to be able to do a whole directory

for file in `ls`; do

stump="`echo $file |sed s?"\.filetype1$"?""?`"

#here I use mv instead of the actual command to stand in for it

mv $file "${stump}.16t"

done
###################
Thanks!
 
Old 02-10-2006, 02:01 PM   #2
DJOtaku
Member
 
Registered: Oct 2004
Location: USA
Distribution: Fedora 20; Arch; Kubuntu; Debian
Posts: 710

Original Poster
Rep: Reputation: 31
currently I have replicated the for ... do loop with a foreach loop.

I just need help on getting

set stump="`echo $file |sed s?"\.filetype1$"?""?`"

to work in csh
 
Old 02-10-2006, 03:14 PM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,506

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Converting a shell script to csh is a loss of time.
 
Old 02-10-2006, 05:34 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
It looks like you want to use 'basename'.

--- rod.
 
Old 02-10-2006, 05:50 PM   #5
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Rather than convert the script (I have to agree with Jlliagre), can't you just:

1. Make sure the right shell is installed ("bash" for Linux, or "ksh" for Unix)
2. Make sure the first line of the script has "!/bin/bash" or "!/bin/ksh"???
 
Old 02-11-2006, 08:41 AM   #6
DJOtaku
Member
 
Registered: Oct 2004
Location: USA
Distribution: Fedora 20; Arch; Kubuntu; Debian
Posts: 710

Original Poster
Rep: Reputation: 31
no alternatives on this machine. Work is very adamant about not installing new things.
 
Old 02-11-2006, 09:16 AM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,506

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
What machine is this with csh and no bourne shell ?
 
Old 02-11-2006, 01:01 PM   #8
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 31
Note that, although you may not have *bash* installed on this machine, you should have *sh* installed. Do "which sh". If it comes up with anything, just take your original script and change #!/bin/bash to #!/bin/sh.
 
Old 02-13-2006, 05:35 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,290

Rep: Reputation: 174Reputation: 174
google "C shell considered harmful"

I would run it as /bin/sh it looks trivial enough to work.
/bin/sh is closer to bash than csh.


It looks a mess, what are you trying to do?
I suspect you are making life difficult for yourself.

for a start you don't need an `ls`
Code:
for file in *; do
 
  


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
Converting extended ascii (,) in bash script Hko Programming 4 12-29-2012 03:42 AM
Script for csh or bash unihiekka Programming 5 10-15-2005 09:51 AM
bash script for converting ps to pdf juergenkemeter Linux - General 3 10-10-2005 04:35 PM
shell confusion..what is diff between bash, ksh, csh, tcsh..?? servnov Linux - Newbie 7 11-18-2004 08:28 PM
BASH vs CSH: * cant see very large files pat57 Linux - Software 6 08-04-2003 02:32 PM


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