connor.roche connor.roche - 11 months ago 119
Bash Question

Can't pass /bin/*

I am trying to pass a to fill an array with a list of directories using a simple shell script. However when I pass

/bin/*
into the program as the first parameter
$1
turn to
/bin/bash
(the first directory in /bin). My code is below for reference. Can I not pass
*
in a parameter?

#!/bin/bash

declare -a d
placeholder=0

for filename in ${1}; do
d[${placeholder}]=${filename:5}
((placeholder++))
done

echo "$1"


The result of the echo is
/bin/bash


Thanks!

Answer Source

* is being expanded by the shell before it calls your script. Try calling as yourscript '/bin/*' (note the quotes).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download