Having trouble with My Bash Script, need Help debugging
Hello Friends
I am having trouble with my script below. I will describe the problems below the code box. I am hoping that some of the experts here can help me.
I haven't found a way around using 'ls' or 'find' in my select statement to produce the Selection Menu. I know that they return unsafe IFS results and that it results in some files having multiple menu entries. I am still looking for a way to combat that issue. However, I would like to have someone look at it for me.
Upon execution of the script, I get some prompts duplicated after performing the task. For instance, after traversing several directories, to finally reach the file that I would like to restore. I am prompted to restore the file. I say yes to restore. I get the echo stating that the file is being restored, then immediately after, I get the same prompt. I know it's something in the functions causing this, but I don't know how to resolve it. Also, while entering a selection at the selection menu, I deliberately entered an invalid choice to see what would happen. It drops to /root and echos "No files exist here!" and prompts to Restore ? [Y/N]?>. I don't know what's causing this or how to fix it. Do you have any ideas about any of this?
Please Note, that this script is not complete. I still have much work to do.
I should also point out that I am working on a Thecus N4100Pro Nas via ssh. The box has a very limited command set, as it is running a dumbed-down version of Slackware. Some options for the commands that do exist, are non-existent on this box. For instance, 'find' with the -maxdepth or -mindepth options. Find is a valid command for the box, but the options do not exist.
Thanks for your help.
Last edited by jdavis_33; 12-19-2012 at 12:59 PM..
Reason: Fixed comment lines in code area and made spelling corrections.
One way to deal with IFS embedded file names in menus is to present them numbered or with radio buttons or on a button so their IFS characters are not an issue. Layout can be a challenge. Make it a web service, call with lynx or such and let the browser table sort it out. You need to be more strict about using quotes, like "$whatever", to keep the IFS characters under control.
Using while for if deprives you of the else. A function is worthwhile if you call the code twice, but for casual efforts with good internal architecture they are rarely needed. Lots of diuplicate code elements should tell you the architcture is sloppy.
Set the PATH right and trust it, not put full path of commands in similar variables. Do not steal/overload variable names already in use by UNIX, e.g., $USER.
Declared functions are not steps, but where they are called maybe a step.
ls -Q might help a little with those IFS characters, if it's implemented in your limited command set.
Probably best to test if a directory is empty before calling select (no point presenting an empty menu). You can trap invalid choices in you select statement something like this:
This User Gave Thanks to Chubler_XL For This Post:
If DIR/* and DIR/.* resolve to DIR/. DIR/.. and DIR/* literally, the first two are ignored and the last is neither dir nor file. No directory is truly empty, . and .. are real entries with real inode numbers. The nullglob part is nice, but is a subshell more costly than a failed directory lookup? As the man page says, nullglob is so unexpected and potentially destabilizing that you always need to restrict it to a subshell.
Last edited by DGPickett; 12-19-2012 at 06:19 PM..
PH=(6H 0 0 JD 9S 0 KD 0) #input from .txt file
In the above array, I am trying to get the computer to tell me at what indices the non-zeros are at.
I don't understand why this doesn't work...
grep -v -b "0" ph.txt > position.txt
Isn't grep -v supposed to show non matches in Bash?... (2 Replies)
hi all
only the weirdest thing happened with me just now. I was debugging a shell script and I found that a step that was supposed to execute later was getting executed prior to another step for no reason. You know any ?
i mean have a look at the following command-
here it tries to grep... (7 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
2. Shell Bash Script
3.
!/bin/bash
if
echo no directory
then
mkdir -p /home/AC_Drywall
elif ; then
echo "$dir already exist"
fi (4 Replies)
Would really appreciate it if someone could point out my mistake in this line of code, i've been staring blankly at it trying everything i can think of some time now and coming up with nothing.
#!/bin/bash
echo "Enter Username"
read Username
awk -F: -v var=${Username} '/^var:/... (9 Replies)
I can do this on the command line:
sqsh -S 192.168.x.x -o tmp -U user -P fakepass -D horizon -C "\
select second_id
from borrower
where btype like '%wsd%'
"
I can also just leave the SQL at the end intact on one line ....
... However, when I throw this in a script like:
$SQSH -o... (4 Replies)
I am trying to create a menu, and the script fails on ln 38 (Files in pwd). Any idea on where the problem is??
Thanks for the help
Rob
#!/bin/bash
# Cool Script for Weekly Assignment 2 (#3) that creates a menu to act as a ui
# and run some popular commands.
clear
while :
do ... (9 Replies)
is there any way you can add a breakpoint in a script so you can stop on it?
i have used -xv in my shebang but the script just runs and i want it to stop at a specific point in the script.
appreciate any help. (1 Reply)
Hi all,
Am working on a script to understand the flow control of it..
Since i am from a C background i looking out for an easy way to analyze the script as it runs ..
In C/C++ we have F7 that starts execution from main() and proceeds accordingly..
I was wondering if there is a same approach... (2 Replies)
Hi all,
Am using bash shell.
Am newbie, trying to understand the debugin process of a shell script...
I am unable to comprehend the control flow ,meaning from where exactly the execution of the script begins...
I tried using bash-xv <scriptname> but since am new ,am finding it difficult to... (2 Replies)