How can I write a script that displays the words "I should have studied" to stdou when run?

How can I enter the contents of a script that when run would display the words "I should have studied" to stdout?

This is my best try:

$ echo "I should have studied" | grep studied

I know that the first statement is necessary for the shell to execute my command. In the second one, I am using echo to print it and then the pipe operator for that command to be redirected to become the input of my other command. I am also using ‘grep’ to find any lines in that list which contain the string directory and to send those lines to standard output. Am I making some progress?

Unix & Linux Asked by PoweredbyGsus on November 11, 2021

1 Answers

One Answer

If you're typing directly at a shell you can

echo "I should have studied"

To create a script, all you do is put the commands you want to be run into a (text) file and use that file:

Using you preferred UNIX/Linux editor, create the file study. You can use any name you like (including one with a .sh suffix if you prefer). Add these two lines to it

echo "I should have studied"

The first line declares that it's a bash shell script. You don't need to filter the output with grep as the echo command does enough all by itself. (Also notice you don't type the leading $; some people use this on StackExchange and other sites to show they're typing a command but personally I think it's confusing.) Now make the file executable so it can run like any other program on the system

chmod +x study

And run it


The leading ./ tells the shell to look for the command in the current directory. If the script was in a system directory or otherwise in your search path ($PATH) you would be able just to type its name, study to run it - just like any other command.

For syntax checking, don't be afraid to use as and when your scripts start to develop.

Answered by roaima on November 11, 2021

Add your own answers!

Related Questions

How to activate v-sync with nvidia linux driver?

1  Asked on February 7, 2021 by chiseledabs


How to set country (region) for WiFi globally in Linux Mint 20?

1  Asked on February 6, 2021 by linuxsecurityfreak


lsblk doesn’t show attached virtual storage / partition

1  Asked on February 5, 2021 by robert-einsle


Samba with multiple shares from the same server

3  Asked on February 5, 2021 by s55michi


increase TrackPoint sensitivity beyond max

0  Asked on February 5, 2021 by modernneo


Can GRUB font size be customised?

5  Asked on February 5, 2021 by neydroydrec


Ubuntu route table: docker entry causes VPN to not resolver

1  Asked on February 5, 2021 by perimosh


Viewing (monitoring) line status of a serial port

1  Asked on February 4, 2021 by anton-samsonov


How to list files – sorted by both filename and modified date?

1  Asked on February 3, 2021 by gabor-faludi


Specify rootfs mount options

1  Asked on February 3, 2021 by iron-oxidizer


Ask a Question

Get help from others!

© 2021 All rights reserved.