Linux shell script program to execute 'ls' command

Here, we are going to learn how to execute 'ls' command in Linux shell script?
Submitted by Nidhi, on February 14, 2021

Problem statement

Here, we will create a shell script program to execute the "ls" command and print the result on the command on the console screen.

Execute 'ls' command

The source code to create a Linux shell script program to execute the "ls" command is given below. The given program is compiled and executed successfully on Ubuntu 20.04.

Linux shell script program to execute 'ls' command

#!/bin/bash

# Program name: "execute_cmd.sh"
# shell script program to execute a "ls" command.
cd /
ls

Now, we will save the shell script program with the "execute_cmd.sh" name.

Output

$ sh execute_cmd.sh 
bin   cdrom  etc   lib	  lib64   lost+found  mnt  proc  run   snap  swapfile  tmp  var
boot  dev    home  lib32  libx32  media       opt  root  sbin  srv   sys       usr

Explanation

In the above program, we executed the "cd" and "ls" commands and print the result of the "ls" command on the console screen.

Linux shell script programs »


Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.