Hi I had a question how to how write a script that would first check to see if a given filepath exists and if so outputs the path in readable sentences. I was going to start with
if [ -e "$1" -a -d "$1" ]; then
echo $PATH
else
echo "Path does not exist"
fi
so basically I'm just a little confuse on when I run my script ./myscript filename how exactly filename gets passed into $1 so I can check to see if it exists. I was also wondering how to do this to see if a user exists on the system. Any help is greatly appreciated!
$PATH, not$1, which is a quite different thing). Please provide a minimal reproducible example that shows how you're invoking it, what you expect it to do, and what it's actually doing instead.-eis a superset of-d, so[ -d "$1" ]will behave exactly the same. Also, note thattest -ais marked obsolescent in the POSIX standard -- best practice is[ -e "$1" ] && [ -d "$1" ].PATHas a name for a user-defined variable -- conflicts caused by that kind of situation are part of why the relevant standard defines POSIX-defined utilities as using only all-caps names, and reserves lowercase names for applications -- such as user-written scripts).