Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jul 232012
 

How to get absolute path in Python?

Answer:

To return the absolute path when you provide shortcut path such as ".", e.g.

import os
print os.path.abspath(".") # print the full path of ., depending where you execute the program
Jul 012012
 

How to find a class in a Jar file

Answer:

To find a class file in a given Java Jar file, e.g. to find the class "KeyToken" in the file "selenium-server-standalone.jar",

# jar -tf selenium-server-standalone.jar | grep KeyToken
org/yaml/snakeyaml/tokens/KeyToken.class
Jun 292012
 

How to ignore error in Bash script

Answer:

We have learned in the past on how to show the exit status of a given command.

But is it possible ignore the error and return normal exit code even the command has failed?

Yes, pipe "|| true" to the end of command, e.g.

# foo || true
-bash: foo: command not found
# echo $?
0

As you can see even the command foo was not found, our last exit code is still zero.