converting ksh scripts to sh


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
converting ksh scripts to sh

Hello All,

I have a whole bunch of shell scripts written in a ksh environment and which successfully execute there. However, I found out that they eventually need to be used in a sh environment. So some commands like some_variable=$(some_command) fail because sh doesn't understand $(.....). I identified a list of scripts that have the $(.....) statements. Now I have to replace all those with `.....`

There must be someway I can automate this find and replace action right? Can you please point me in the right direction? Can I use sed for it? If so, what is the exact command? I can identify the statements using the regex '\$(.*)' but I don't know how to replace the command with `...`
I guess I have to parse each line of each file in a loop and do the substitution but I don't know the substituion command.
Thanks in advance for ur help.Smilie
# 2  
Or can you acquire/compile ksh for that environment?
# 3  
thanks for ur response. unforunately, i am not in a position to change the ksh environment to sh although that would be wise to do Smilie.
# 4  
What will the deployed OS be? It may be that there is a POSIX shell in that environment that will handle most or this syntax, reducing the amount of changes you will need to do.
# 5  
reborg, I'm just a shell programmer and the OS is solaris (which I access using putty from windows). Both sh and ksh seem to be installed (I can execute both from prompt). Should I use a C solution (pressed for time)? Thanks in advance.
# 6  
Quote:
Originally Posted by sherkaner
Both sh and ksh seem to be installed.
Then why not use "ksh" if you have it?

To me it is madness to have working scripts, that then you have to rewrite just to use a different shell when they can be called as child processes by shell scripts of any other flavour.

If time is pressing why make what sound like tens or hundreds of changes that then require regression testing? It sounds like you are basically taking working production scripts and turning them into development projects.

So, you do the simple changes, then what about array variables and all the other ksh features?

Your trust and faith in these new scripts should be at rock bottom until they are fully tested, not exactly the thing to do if you are pressed for time.
# 7  
wise counsel, porter. Thanks.

However, the scripts are for the 'production system' which apparently does not have ksh, while the development system does (Don't ask me why). That is why I am scrambling to convert them here. Most should be simple in that they don't use arrays. Only thing that I can think of is the issue with $(...) commands. Any other issue should be caught by the testing people - not expecting too many though. I had this shell differences thing in the back of my mind when I made the scripts but I guess I was not wary enough/ didn't have enough information about the differences.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #860
Difficulty: Medium
Vue.js is an open-source JavaScript framework for building user interfaces and single-page applications.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

converting ksh to bash - typeset commands

Hi all, Am trying to convert a script written in ksh to a bash shell. At the moment, am stumped with the typeset -u command and I can't find an equivalent of it in bash. integer function is also not working as is the following if statement if ] && ]; then continue fi Is... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. UNIX for Dummies Questions & Answers

converting scripts from dos 2 unix format

Hi, I am new to shell scripting and exploring it , I have developed few sample shell script but I have developed them on windows xp notepad and then saving them on folder and then testing them on cywgin and running perfectly...but these scripts are in dos format and I want to convert them in unix... (1 Reply)
Discussion started by: rahul125
1 Replies

3. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

4. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

5. UNIX for Dummies Questions & Answers

Converting binary file to readable format in Ksh

In Unix/Ksh, when I try to look inside a file it says that the file may be a binary file and if I want to see it anyway. When i say 'yes', it shows me the content filled with unreadable symbols (looks like binary). Is there a command that I can run from the Unix prompt to convert/translate that... (3 Replies)
Discussion started by: arthurs
3 Replies

6. Shell Programming and Scripting

HELP WITH .ksh script converting the exit status

Hi Can someone help me please? In a standard UNIX .ksh script, if you have the exit status..say 5...what line do you have to enter into the script for this number to be automatically converted to its actual exit reason by looking up the exit status file...wherever that is? thanks angus (1 Reply)
Discussion started by: angusyoung
1 Replies

7. Windows & DOS: Issues & Discussions

converting ksh scripts--.bat in window's

hi evry one , I did some ksh scripts for file editing in AIX 5.2 ver, issue is while I was trying to run these scripts in windows box as batch files windows is not recognising the awk part of the ksh script,as it is GNU environment, so any one who can help me will be appreciated. this is the... (3 Replies)
Discussion started by: 2.5lt V8
3 Replies

8. Windows & DOS: Issues & Discussions

Converting UNIX scripts to DOS

Is there a tool available to convert UNIX (BASH Shell) scripts to DOS scripts? I understand that DOS scripting is far inferior to unix scripting, and therfore this conversion may not be possible. Alternativley, perhaps I could convert my Unix scripts to C... then compile it for a windows... (2 Replies)
Discussion started by: Crozz
2 Replies

9. Shell Programming and Scripting

Converting Text File into XML using Unix Shell Scripts

Hi everyone, If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert a file into xml format using Unix shell scripts. The file has fields with each field having a certain number of bytes, but the fields are not delimited by anything... (10 Replies)
Discussion started by: Laud12345
10 Replies

10. Shell Programming and Scripting

Converting an OpenVms .com to a UNIX ksh script

Does anyone know what a unix equivalent to the following OpenVms string would be? variable1 = F$FAO("!123AS",file_create_time) I can't seem to find the proper syntax of anything I try. Thx! J (1 Reply)
Discussion started by: prosserj
1 Replies

Featured Tech Videos