User420
User420

Reputation: 137

Shell Script unclear usage of " : "

I have been trying to alter an old Shell Script for my project. I have done some researching but the usage of : in shell script but is quite unclear to me.

#!/bin/bash

cd /home/dir1/dir2/dir3

FILES=../lib/*

CLASSPATH=.:../conf/

for f in $FILES
do
    CLASSPATH=$CLASSPATH:$f
done

echo $CLASSPATH

What are they trying to do here, is it looking for same named files in both directories and assigning them to CLASSPATH?

Upvotes: 2

Views: 98

Answers (2)

Mischa
Mischa

Reputation: 1333

: is a separator for the CLASSPATH.

Your script basically:

  1. Sets the current directory to /home/dir1/dir2/dir3
  2. Assigns ../lib/* to FILES
  3. Assigns . (the current directory) and ../conf to CLASSPATH (separated with the :)
  4. For every file in FILES sets the CLASSPATH to itself (to keep the old value) and append the path of the found file (again separated with the :)

Upvotes: 6

songyuanyao
songyuanyao

Reputation: 172894

: is separator.

So what they're doing is get all the file in the directory ../lib, and append them all to CLASSPATH by for loop.

Upvotes: 1

Related Questions