I was wondering how this looks. I am trying to create a script that will produce a text file that has a list of the files in the present working directory. How do you go about testing this script?

#!/bin/bash
#
# Matthew Smith# Comp230
ls >FILE.txt

Save the file with a .sh extension, then add executable permissions:

$ chmod ugo+x shell-script.sh

Now run it:

$ ./shell-script.sh

Note that your current directory doesn't have to be where the script is to run it:

$ /some/path/shell-script.sh

I am a little confused as what program you need to run this code?

Also I need some help here with this code. I need to create a bash script that will copy all the files and subdirectories in one directory to a newly created directory. Here's what I came up with.

cp -R dir/*newdir/*

You pretty much have your entire script right there, assuming you don't need to be any more creative, just add a

#!/bin/bash

line to the top and make it executable, etc, per the above post by John A

Best wishes,

Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.