Change Shell Command Path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change Shell Command Path
# 1  
Old 10-18-2011
Change Shell Command Path

I want to change the path for the command in a shell. I want to make it easier to type in the command when I run the shell. As of now, I have to type in /bin/ls but I want to just type in "ls" instead. I have altered the function below to do this but it's not working. It still must have the full path. What am I doing wrong? Is it a syntax error?

Code:
void get_path_string(char **tmp_envp, char *bin_path)
{
  int count = 0;
  char *tmp;
  while(1) {
    tmp = strstr(tmp_envp[count], "LD_LIBRARY_PATH");
    if (tmp == NULL)
      {
            count++;
            continue;
      }
    else
      {
        break;
      }

    //tmp = strstr(tmp_envp[count], "PATH");
    //if(tmp == NULL) {
    //  count++;}
    //  else {
    //  break;
    //}
  }

  strncpy(bin_path, tmp, strlen(tmp));
}

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by vbe; 10-18-2011 at 12:55 PM..
# 2  
Old 10-18-2011
On what machine? What OS?
All UNIX have PATH environment set to by default a strict minimum which includes /bin:/usr/bin...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to change the path location within the shell script?

Hi ALL, I am trying to find the installed tomcat version and location of the server.xml file to get the tomcat port number. Using below script to do that. #!/usr/bin/env bash var1=$(find / -name "version.sh" ! -size 0 2>&1 |egrep -v "tmp|docker") for loc1 in $var1 do ... (1 Reply)
Discussion started by: sravani25
1 Replies

2. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

3. UNIX for Dummies Questions & Answers

Extract name from path and change output

Dear All, I would like to extract the file name without extension form a variable... In particular I have a command like this one: for file in path/to/file/example_number.ext do something -input $file -output ${file%_number.ext}.new done means that in variable $file are saved all the path... (3 Replies)
Discussion started by: giuliangiuseppe
3 Replies

4. Shell Programming and Scripting

command to change the shell

Hi, I want to change the shellrite now I am in ksh shell , I want to switch to bash shell I have tried the command ... $ chsh -s /bin/bash but it is showing error .... -ksh: chsh: not found (1 Reply)
Discussion started by: rahul125
1 Replies

5. SuSE

change PATH problem

Hi, I want to add a path to PATH. I added export PATH=$PATH:$HOME/newpath in the ~.profile. I exit the shell and reenter shell. After I type echo $PATH. The new path is not added. I don't know why. Can someone give advice? Thanks! (3 Replies)
Discussion started by: jianma
3 Replies

6. Shell Programming and Scripting

How to change Absolute path to Relative path

Hello, I have a doubt:- --------------------- Current script:- ################################################################################################ prefix=user@my-server: find . -depth -type d -name .git -printf '%h\0' | while read -d "" path ; do ( cd "$path" || exit $?... (4 Replies)
Discussion started by: sahil_jammu
4 Replies

7. Shell Programming and Scripting

how can i change my PATH

1. that you are calling the POSIX UNIX commands located under /usr/xpg4/bin instead of those under /usr/bin 2. that you can run programs from the current directory 3. that your scripts located in the bin directory under your HOME directory can be found and executed from any... (1 Reply)
Discussion started by: vpatel44
1 Replies

8. HP-UX

change directory path

Hi, when ever i login my unix system it is going to root directory....how can i change it specified directory.. (3 Replies)
Discussion started by: rsivasan
3 Replies

9. Solaris

How to permanatly change PATH

I used set PATH$ but that worked until I closed Terminal , now qouestion is how to put this in... (7 Replies)
Discussion started by: microbot
7 Replies

10. UNIX for Advanced & Expert Users

Change Default Path ?

Dear All When i am telnet' ing to some IP, after logging in, i am into some default path.I want to specify "custom path" , that is after logging in , when i do pwd it should be custom path.For this where i have to change the setting or edit the path already specified. I am having... (4 Replies)
Discussion started by: tkbharani
4 Replies
Login or Register to Ask a Question