Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The first thing to pop into my head to change just part of a string is a sed substitution.</p> <p>example: if echo $PATH => "/usr/pkg/bin:/usr/bin:/bin:/usr/pkg/games:/usr/pkg/X11R6/bin" then to change "/usr/bin" to "/usr/local/bin" could be done like this:</p> <p>## produces standard output file</p> <p>## the "=" character is used instead of slash ("/") since that would be messy, # alternative quoting character should be unlikely in PATH</p> <p>## the path separater character ":" is both removed and re-added here, # might want an extra colon after the last path</p> <p>echo $PATH | sed '=/usr/bin:=/usr/local/bin:='</p> <p>This solution replaces an entire path-element so might be redundant if new-element is similar.</p> <p>If the new PATH'-s aren't dynamic but always within some constant set you could save <em>those</em> in a variable and assign as needed:</p> <p>PATH=$TEMP_PATH_1; # commands ... ; \n PATH=$TEMP_PATH_2; # commands etc... ;</p> <p>Might not be what you were thinking. some of the relevant commands on bash/unix would be:</p> <p>pushd popd cd ls # maybe l -1A for single column; find grep which # could confirm that file is where you think it came from; env type</p> <p>..and all that and more have <em>some</em> bearing on PATH or directories in general. The text altering part could be done any number of ways!</p> <p>Whatever solution chosen would have 4 parts:</p> <p>1) fetch the path as it is 2) decode the path to find the part needing changes 3) determing what changes are needed/integrating those changes 4) validation/final integration/setting the variable</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload