How can I check if a command can be successfully executed without actually executing it? For example, if i want to connect to another host using telnet connection, how do i check if telnet client exists or not? Or if I want to do a cp or mkdir or rmdir, how do I check if any of these commands can be valid before executing them?
-
Access the system PATH variable, split by folder-name, and check to see if foldername+command exists?kufudo– kufudo2013-03-28 08:53:03 +00:00Commented Mar 28, 2013 at 8:53
-
you could also try if exists also if you type if/? in cmd you can find some info thereCMS_95– CMS_952013-10-11 01:01:58 +00:00Commented Oct 11, 2013 at 1:01
Add a comment
|
1 Answer
You can always run
which telnet
this will tell you the actual file that would be executed. However, it will not tell you if the command will run with success. For instance, which cp will only tell you where the executable is and not if the files being copied exist and you have the right to copy them to the chosen destination.
Hope this helps
1 Comment
AlwaysALearner
So, in general, if there is a
<command_name>, i need to check if <command_name> exists or not by executing which <command_name>. Is that what you are saying?