Test || How Create/Execute Shell Script in Linux?

This purpose of this article is for testing my simple shell script in Linux.

Steps:

  1. Create a simple shell script
  2. Execiting script shell in terminal

It’s simple. Let’s get started!

Create a simple shell script

To craete a shell script: vim name

  • You can type below examples for testing your script.

Note: “vim” provides another verifications of programming language comapred with “vi”. Although you can use both to create your shell script.

Example 1:

1
2
3
echo "Hello $USER."
echo "Today is $(date)"
echo "Current working directory : $(pwd)"

Example 2:

1
2
3
4
5
echo "What is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"

Create script

  • After typing your shell script, save it.

To save it, press “Esc” to exit the insert mode and type “:w” to save the script.

:w - to save

Type “:q” getting back to the console and execute the shell file to show output in the terminal.

:q - to quit

“ls” to check if the shell script had been created successfully.

ls - to check script

To execute a shell script

“bash” to execute the schell script

bash - to execute script

Follow above simple steps to run your own script. :P

© 2022 Tiffany's Blog All Rights Reserved. 本站访客数人次 本站总访问量
Theme by hiero