shell script
hi guys i have a big problem i want to write shell script that give back argument is file or directory
how can i do it e.q ./dfsh asd give back its file or ./dfsh /home/asd give back its directory in other word if argument contain "/" echo it's directory regardless of it's exist or not |
man bash contains some useful information on boolean operators for files.
Here's what you need, with some comments: Code:
#! /bin/bash |
You mean just to check if the variable passed contains "/" or not?
You can use the operator =~ : Code:
#!/bin/bash Hope this helps, |
Quote:
echo $1 | grep "/" 1>/dev/null if [ $? = 0 ] then echo "Yes" else echo "No" fi but your work is must bettre |
Just as long as you realise that this in no way indicates if it is a file or directory???
The OPs own example is flawed if we assume that asd is in the home directory: Quote:
only about its location. avingard's examples are more correct |
Quote:
Code:
echo $1 | grep -q \/ && echo Yes || echo No Code:
if echo $1 | grep -q \/ |
Quote:
|
Thanks Snark ... missed that bit :(
|
All times are GMT -5. The time now is 08:40 AM. |