ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

grail, pls forgive me ignorance for not able to recognise the updated code from crts.
Thanks PMP for your code too.

It may make sense to reveal the actual concept of this script. The script is required as we have a bunch(nearly 100) of scripts written for HP-UX OS. And the person who wrote the scripts added the absolute path for each of the system commands (eg., for 'basename' he wrote as '/usr/bin/basename').

Now we are moving the server from HP-UX to Linux and because of these absolute paths attached to the commands, they might not work due to compatibility issues. So what i am trying to do is to insert a new line(PATH variable) into each of these scripts and strip off the absolute paths attached to each of the system commands in the script.

That is the reason for my request. I apologize for confusing you guys. But really appreciate your patience and time to respond to my queries.

I dont think that will be a problem because the user who will be executing the scripts will have the env set on login. And more over, as part of this script, we are inserting the line (export PATH=$PATH:..../.../...etc) at the top of each input script. So that shud solve the issue.

the compatibility issues are ... the commands actual location is different from HP-UX to Linux.

As this is a migration, I personally would like to keep the absolute paths as there as chances that these scripts will be executed by user whose path variable is not set to read the commands.

Until recently I used to fervently believe that; all my big scripts had an initialisation function, setting up a variable for each command (like ls=/bin/ls) and then testing them all to ensure they were set to an executable ordinary file.

Now I'm coming to think that the effort of doing that is not justified by the benefits and that a better solution is to explicitly set $PATH in the script, remove all aliases and then use command names without leading paths.

the compatibility issues are ... the commands actual location is different from HP-UX to Linux.

Which suggests solution by having a table of command fullpaths which differ and then replacing only those (with Linux fullpaths or with bare command names and then rely on $PATH; for consistency within the script the first has appeal).

A much harder issue to address is commands which take different options and harder than that are commands which produce differently formatted output (which is parsed by the scripts in a format-dependent way).

Yes. I agree with PMP. As the scripts are written a long time ago and we dont want to play with them.

As far as the "command paths that are changing" is concerned, they all are system commands and hence will be lying in standard paths like /bin, /usr/bin, /sbin etc. So we are including these in the PATH and inserting the same in each file.

Yes. I agree with PMP. As the scripts are written a long time ago and we dont want to play with them.

As far as the "command paths that are changing" is concerned, they all are system commands and hence will be lying in standard paths like /bin, /usr/bin, /sbin etc. So we are including these in the PATH and inserting the same in each file.

Actually, in post #21, I was suggesting the least "playing with them". Rather than try and remove all paths with the possibility of collateral damage I was suggesting replacing only the specific paths that are different HP-UX/Linux.

If, for example, /usr/bin/ls on HP-UX was /bin/ls on Linux then you would change exactly that -- and so on for every other command identified as having a different path.

If I understand correctly, processing the file with sed is a onetime activity that you are doing, bring on the scripts to linux, make the modifications with the sed command that you are doing, copy the modified version back to HP-UX