13

I was trying to access redis-cli but because i'm that lazy i typed red and hit tab twice, but i noticed that there's a binary actually called red which is located under /bin/.

When I did

cat /bin/red

it showed

#! /bin/sh
bindir=`echo "$0" | sed -e 's,[^/]*$,,'`
exec "${bindir}"ed --restricted "$@"

Any idea what that is?

Note. when i execute red, it just waits for an input and whatever i type in, it either saves it and waits for another prompt or returns ?, note that only when hitting q it exits. also when inserting numbers from 0-9 and keep enter it shows every input you inserted when it saved what you typed earlier

example:

a <<<-- input
bsa <<< input taken without ?
^C <<<--- hitting ctrl-c
?  <<<--- output

example2:

v
?
b
?
a
qwrefdf <<-- saved because it didn't output ? after typing "a" up
^C
?
 <<- waiting for input

so "h" outputs in "invalid address" and only "a", "x", "c" and "i" accepts input. everything else other than numbers results in ?

  • 3
    For what it's worth, you could answer this question yourself by running the command dpkg -S /bin/red. This will tell you that the file is part of the ed package, and apt-cache show ed will give you a description of that package. – David Jul 8 at 22:16
  • 3
    Very important : don't execute blindly some application you don't know. Even Linux has malware... – Goufalite Jul 9 at 6:26
  • 7
    Ed is the standard text editor. gnu.org/fun/jokes/ed-msg.html – IMSoP Jul 9 at 9:02
  • 4
    Or even more straightforward: man red. – OrangeDog Jul 9 at 15:42
  • @IMSoP I like how in the joke they made vi ridiculously large at 1.3MB. Fast-forward almost 30 years, and the vim binary on my system is actually twice the joke size at 2.7MB :') – marcelm Jul 9 at 16:18
29

red is ed in restricted mode.

$ whatis red
red (1)              - line-oriented text editor

$ man red
shows `ed` man page.

Also, the code shows, it executes ed --restricted from bindir with all arguments ("$@").

For a manual on ed and its commands, run info Ed.

In the chapter Invoking ed:

The format for running 'ed' is:

 ed [OPTIONS] [FILE]
 red [OPTIONS] [FILE]

[...]

'-r' '--restricted' Run in restricted mode. This mode disables edition of files out of the current directory and execution of shell commands.

  • Useful commands for producing some of the information in this answer: file /bin/red and cat /bin/red (since file shows that it's a "POSIX shell script, ASCII text executable). – Dennis Williamson Jul 9 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.