Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sed command not found

Tags:

bash

shell

I have this code:

if [ -d "$PATH" ]; then
ABSPATH=$( cd "`echo "$1" | sed 's/[^/]*$//'`";pwd)
fi

when I run it, I get this sed: command not found.Any command I put inside this "if" blog writes this message, XXX:command not found. I have no idea why. I have exactly the same code elsewhere in my script and it is fine there.

like image 361
sykatch Avatar asked Mar 29 '15 21:03

sykatch


People also ask

What is the command for sed?

The sed command stands for stream editor in UNIX-based systems. It performs text editing operations on text coming from the standard input or a file. It can perform operations such as deletion, searching, find and replace, or insertion in a file even without opening it.

Does sed work on Linux?

The SED command in Linux stands for Stream EDitor and is helpful for a myriad of frequently needed operations in text files and streams. Sed helps in operations like selecting the text, substituting text, modifying an original file, adding lines to text, or deleting lines from the text.


1 Answers

The nature of your program* snippet implies that you have just overwritten PATH. PATH is an important environment variable that lets the shell know where to find commands… commands like sed. If you overwrite it, sed will not be found.

Use another name; even lowercase path will work fine.

*I'm fairly confident that you overwrote PATH because PATH should not be a directory – it should be a colon-separated list of directories. If [ -d $PATH ] is true it either implies you have a very restrictive context for PATH, or, more likely, you have overwritten it.

like image 112
kojiro Avatar answered Sep 30 '22 17:09

kojiro