Beginner Bash scripting question? FASTEST CORRECT ANSWER GETS BEST ANSWER ***?
-
This is my script, I am trying to write a script to take a PID as a parameter, and display the parent PID of it, and the parent PID of its parent PID, all the way until I get back to process 1. Basically, showing the lineage of any PID back to process 1. Please let me know what I'm doing wrong. #!/bin/bash if [ ! -d /proc/$1/ ]; then echo "That is not a valid PID" elif [ ! $# -eq 1 ]; then echo "I need one PID parameter" else echo $1 helper $1 fi function helper{ declare -i TEMPVAR=$(grep "PPid" /proc/$1/status | cut -c 7-) echo $TEMPVAR if [ ! $TEMPVAR -eq 1 ]; then helper $TEMPVAR fi } This is my first attempt at a function, and when I try to run the script I get line 9: helper: command not found line 13: syntax error near unexpected token 'declare' line 13: 'declare -i TEMPVAR=$(grep blah blah)' Please Help!!! First correct answer gets best answer.
-
Answer:
#!/bin/bash if [ ! -d /proc/$1/ ]; then echo "That is not a valid PID" exit fi if [ ! $# -eq 1 ]; then echo "I need one PID parameter" exit fi # specified pid: echo $1 # next pid up the tree: TEMPVAR=$(grep "PPid" /proc/$1/status | cut -c 7-) while [ ! "$TEMPVAR" = "1" ]; do TEMPVAR=$(grep "PPid" /proc/$TEMPVAR/status | cut -c 7-) echo $TEMPVAR done
coffeeho... at Yahoo! Answers Visit the source
Related Q & A:
- In a job interview: What is the best answer when asked on weakness?Best solution by Yahoo! Answers
- How can I give the best answer in Yahoo answers?Best solution by Yahoo! Answers
- What's the best answer for why you left a previous job?Best solution by Yahoo! Answers
- Why must we wait 4 hours before we can choose BEST ANSWER?Best solution by Yahoo! Answers
- Why Can't I Choose 'Best Answer' Anymore?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.