0

I'm puzzled over some terminology used in my homework:

So, the way I understand the question is that I should print echo, cat, etc., which I would do like with the echo command, for example

echo echo
echo cat 
echo ´!!´

Is that what is meant by "is printed on standard out"?. Am I on the right track here?

Then, I don't know what is meant by "nothing is printed on standard error when the command is entered".

  • And, yes, "nothing more" in the output means "nothing more"., does your teacher mean that there shouldn't be a newline at the end of the string blotz? – terdon Sep 6 '15 at 11:55
  • 1
    @Terdon given the requirement I suspect it would be tricky - if not impossible - for at least one of the commands to output the text without a newline. It's a good catch though – roaima Sep 6 '15 at 13:18
  • @roaima not at all. We're allowed to use extra commands as well so we could just parse it out. – terdon Sep 6 '15 at 13:35
  • The edit-history has the wording of the actual homework assignment, which the OP took out so google wouldn't find this. This leaves the question very unclear, so look at the history. – Peter Cordes Sep 10 '15 at 1:11
2

I believe that you should interpret this homework as meaning that you need to output the word blotz using each of the commands echo, cat, ls, grep, and !! in turn.

The trivial case is echo blotz of course.

The cat command can be considered to output the contents of a file. (man cat may be helpful here.) Your homework permits you to prepare a file beforehand for you to output, so again this should be very straightforward.

The others will take some thinking about to achieve the necessary result.

  • Dear roaima, thank you for your response. So just to make sure I understand, with cat for example, I could create a text file with the text blotz on it, and then i say cat textFileName...like that? – Haz Sep 5 '15 at 23:12
  • @Haz that would work, yes. – roaima Sep 5 '15 at 23:13
  • Sukminder....interesting, so they were trying to trick us there I guess. If I just say echo blotz it will still print the newline character, which it seems they don't want – Haz Sep 5 '15 at 23:37
  • 1
    Hello again @roaima . I created a text file with blotz on it, so i I say grep blotz textFileName , then it prints blotz . Pretty similar in easiness to "cat" but you said this would require more thinking, am I doing something wrong? – Haz Sep 6 '15 at 0:32
1

The question tells you to use each of a list of commands and make that command print the string blotz and nothing else. If your teacher wants to have a newline printed after each blotz (which is not clear from your question), you could do:

$ echo "blotz"
blotz
$ echo "blotz" > file && cat file
blotz
$ touch blotz && ls blotz
blotz
$ echo blotz | grep b  ## This might also include (invisible) color codes
blotz
$ echo blotz | grep --color=never b ## This one avoids the color codes
blotz

Using !! is trickier since, by default, it will also print the command run. For example:

$ blotz      ## run blotz to get that saved as !!
blotz: command not found
$ echo !!  ## print the value of !!
echo blotz ## Unfortunately, this also prints the command being run. 
blotz

To get around that, you could make a little script:

set -o histexpand
set -o history

blotz
echo !!

And then run it like so:

$ bash foo.sh 2> /dev/null 
blotz

There might be a clever hack for this using subshells but I haven't been able to find it.


If your teacher doesn't even want the newline, use these instead:

$ echo -n "blotz"
$ echo -n "blotz" > file && cat file
$ touch blotz && ls blotz | tr -d $'\n'
$ echo blotz | grep --color=never b | tr -d $'\n'

And for the !! script:

$ bash foo.sh 2> /dev/null | tr -d $'\n'
  • thank you very much! I´m new to this website, and so far I've learned linux basics. I think to this point in the hw, we are not supposed to use scripts just yet (that is the next part of the hw). I was thinking I could get rid of the undesired output that !!produces by only selecting the second line of the output, do you know how to do that? Thanks – Haz Sep 7 '15 at 0:02

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.