Santagotthejuice
Santagotthejuice

Reputation: 27

I'm having issues in running this bash script

Hello guys so I was trying to create a script that lists all files in the current directory, the parent of the working directory, and the /boot directory here is what I tried

#!/bin/bash
ls -la ls -la ../ ls -la /boot

I have already made the file executable. The problem comes in when I run it. The error states;

ls: cannot access 'ls': No such file or directory

What could I be doing wrong?

Upvotes: 0

Views: 129

Answers (1)

0x5453
0x5453

Reputation: 13589

The problem is that ls -la ls tells the ls command to look for a file or directory named ls, which doesn't exist.

If you want multiple commands on one line, they must be separated with a semicolon (;).

ls -la; ls -la ../; ls -la /boot

If you split the commands onto multiple lines, the semicolon becomes optional:

ls -la
ls -la ../
ls -la /boot

Or you can just pass multiple directories to ls like so:

ls -la . ../ /boot

Upvotes: 2

Related Questions