LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-23-2019, 04:06 AM   #1
jyothinagendra
LQ Newbie
 
Registered: May 2019
Posts: 5

Rep: Reputation: Disabled
Post Need help


Hi I am newbie to Linux and I need to learn Linux programming .
I need to write a function and try to debug that fuction .
How can I debug the function in Shell script .
Please help me on this .
 
Old 05-23-2019, 04:09 AM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 8,018
Blog Entries: 5

Rep: Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872
Hi jyothinagendra, and welcome to LQ.

You need to give us more information on what you are trying to achieve. Which script are you trying to debug?

Also, in future, I would suggest that you use a more helpful thread title. "Need help" is not very useful and tells people nothing about your issue before they open the thread. "Need help with debugging Shell script" would, for example, have been better.
 
Old 05-23-2019, 06:43 AM   #3
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 4,119

Rep: Reputation: 1152Reputation: 1152Reputation: 1152Reputation: 1152Reputation: 1152Reputation: 1152Reputation: 1152Reputation: 1152Reputation: 1152
Quote:
Originally Posted by jyothinagendra View Post
How can I debug the function in Shell script .
You can use set -x in the shell script, which makes the shell print each command as it is executed. This is switched off with set +x. Running the script with the -x option (sh -x SCRIPT) has the same effect.

The other debugging tool is echo.

The Bash guide in my signature also has a debugging section that suggests more tools: https://mywiki.wooledge.org/BashGuid...ices#Debugging.

In case you have a particular problem you need to solve, you can also describe it here, as hydrurga suggests.

Last edited by berndbausch; 05-23-2019 at 06:46 AM.
 
3 members found this post helpful.
Old 05-23-2019, 06:50 AM   #4
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,431
Blog Entries: 3

Rep: Reputation: 2206Reputation: 2206Reputation: 2206Reputation: 2206Reputation: 2206Reputation: 2206Reputation: 2206Reputation: 2206Reputation: 2206Reputation: 2206Reputation: 2206
In addition to the above useful replies, especially set -x, I'd also point you to the ShellCheck web site.

If you're looking for online guides, I'd recommend these resources, among others:

What have you gotten written so far and where are you stuck? If you post your script here for assistance, please remember to wrap it in [code] [/code] tags so that the indentation is retained.
 
3 members found this post helpful.
Old 05-23-2019, 09:26 AM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 8,424
Blog Entries: 13

Rep: Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741Reputation: 3741
Welcome to LQ.

One of the links in my signature covers bash script debugging methods.

Enjoy!
 
Old 05-23-2019, 09:38 AM   #6
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,001
Blog Entries: 1

Rep: Reputation: 846Reputation: 846Reputation: 846Reputation: 846Reputation: 846Reputation: 846Reputation: 846
For bash you run it with -x. Or debug it the hard way by adding echo's after every line to show location and values of interest. For other compiled languages you need to use gdb. Plus compile the program with debugging turned on.
 
Old 05-24-2019, 04:50 AM   #7
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,645

Rep: Reputation: 278Reputation: 278Reputation: 278
Smile

Quote:
Originally Posted by berndbausch View Post
You can use set -x in the shell script, which makes the shell print each command as it is executed. This is switched off with set +x. Running the script with the -x option (sh -x SCRIPT) has the same effect.

The other debugging tool is echo.

The Bash guide in my signature also has a debugging section that suggests more tools: https://mywiki.wooledge.org/BashGuid...ices#Debugging.

In case you have a particular problem you need to solve, you can also describe it here, as hydrurga suggests.
Agree with "echo", putting it on the right place to spit out value or message is a good way to debug. Of course, mileage will vary you can't put the echo just anywhere.

This link might help: http://tldp.org/LDP/Bash-Beginners-G...ect_02_03.html
 
Old 05-28-2019, 01:21 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,700

Rep: Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494
Personally I like 'set -xv' for a bit more info - YMMV
 
Old 05-28-2019, 05:17 AM   #9
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,001
Blog Entries: 1

Rep: Reputation: 846Reputation: 846Reputation: 846Reputation: 846Reputation: 846Reputation: 846Reputation: 846
Code:
#!/bin/bash

PARM1="b0rked"
PARM2="fitz"
f_HW() {
  echo "Hello World"
  echo $PARM1" "$PARM2
}

PARM1="broke"
PARM2="fix"
f_HW

exit 0
*sigh* homework... Do the kids even do that anymore?

*sigh* books... Do kids even know what those are? At work we flip material "like a book" to print on the second side correctly. The blank stares I get when I explain, like a ????.
 
Old 05-29-2019, 12:59 AM   #10
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,645

Rep: Reputation: 278Reputation: 278Reputation: 278
Quote:
Originally Posted by Shadow_7 View Post
Code:
#!/bin/bash

PARM1="b0rked"
PARM2="fitz"
f_HW() {
  echo "Hello World"
  echo $PARM1" "$PARM2
}

PARM1="broke"
PARM2="fix"
f_HW

exit 0
*sigh* homework... Do the kids even do that anymore?

*sigh* books... Do kids even know what those are? At work we flip material "like a book" to print on the second side correctly. The blank stares I get when I explain, like a ????.
Oops..good spot. The poster ask the question like a pro. hahaha.

homework... Do the kids even do that anymore? Yes they do, they use Wat - t - pad hahaha
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help setting up my vms, hypervisor is KVM. I'm new to netowrking please help. Please Help. I need all the smart guys here!!! fromwin2lin Linux - Server 1 09-07-2016 05:31 AM
Help, help help help help drknownothing Linux - Networking 2 10-24-2004 04:05 AM
help, help, help, help, help....cmi8738 will not work... AMArt79196 Red Hat 2 07-05-2004 07:13 PM
Need some help... need to install a firewall gurusmaran Linux - Software 1 05-16-2002 04:54 PM
need help....need help mercury Linux - Software 2 09-29-2001 12:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration