Sponsored Content
Full Discussion: Bash Script issues
Top Forums Shell Programming and Scripting Bash Script issues Post 302519702 by alindner on Wednesday 4th of May 2011 08:45:00 PM
Old 05-04-2011
Bash Script issues

So what i am trying to do is write a script that takes in any number of scrambeled words and unscrambles them.

I have already addressed the issues of partial matches, exits silently if there are no matches, and finds words regardless of case that they were input. but while trying to get it so that letter counts matched, so a word with two 'ss' would not get results with anything more or less than two 'ss', but i ran into an issue where my loop is dropping my last egrep when i run my eval cmd...Smilie

I cant seem to figure out why the echo shows the right command but when it evaluates the command it loses the last part?

I also am working on the need for if a word is entered with nin alpha characters and to ignore it and out put a message, and error handling so that no bash errors are thrown.

My code with debugging run to show how its dropping the last command
Code:
 
     1  #!/bin/bash
     2  echo "This Script interprets each input entered and descrambles the letters to determine the words that match. :)"
     3
     4  #[[ -z "$1"]] && echo "You must input 1 or more scrambled words to be unscrambled." && exit 1
     5
     6  until [ -z "$1" ]; do #Continue to take in parameters until none left
     7    word=$1
     8    len=${#word}
     9    cmd="egrep -i \"\<[$word]{$len}\>\" /usr/dict/words"
    10
    11
    12
    13      for x in $(seq 0 $((len-1))) ; do
    14        while [ -n "$word" ]; do
    15
    16          ltr=${word:0:1}
    17          nxt=${word//[^$ltr]/}
    18          cnt=${#nxt}
    19          re="$cmd"
    20
    21            if  [ "${cnt}" -gt "1" ];
    22              then cmd="$re |egrep -i \"((${ltr}.*){${cnt}})\"";
    23              #cmd="$re |egrep -i \"((.*${ltr}){${cnt}})\""
    24            else
    25                cmd="$re|egrep -i \"(${ltr}.*)\"";
    26            fi
    27
    28          #echo $cmd
    29
    30          word=${word//$ltr/}
    31          len=${#word}
    32        done #End of for loop
    33      done #End of for loop
    34
    35    echo $cmd
    36    eval "$cmd" #Evaluate Regular Expression
    37    shift #Shift parameters by 1
    38  done #End of Until loop

Ok, i fixed the last issue, i had eval evaluating the wrong string set. I still need some help with interpreting the non alpha's if someone can help.

Last edited by alindner; 05-04-2011 at 09:51 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

IP connection Bash script issues

Hello I need assistance with a bash script that needs to tell me whether in the last "x" days (which is a variable) anyone connected to the xxxx IP (which is another variable). Thank you! (1 Reply)
Discussion started by: Melchiah
1 Replies

2. Shell Programming and Scripting

for / foreach syntax issues (in bash or tcsh)

So I am new to unix, and actually anything outside drag and drop with the mouse (been learning for about a week so far) . I have been using the foreach command in tcsh because I am working on a group of files. Basically what I need is to insert part of the filename as the first line in the file.... (0 Replies)
Discussion started by: thepolypore
0 Replies

3. Shell Programming and Scripting

Bash script issues

Hi. The below part of my bash script kicks out the following error message: $ ./extract_eod_report_stats_new.sh 2010-04-23 ./extract_eod_report_stats_new.sh: line 204: syntax error near unexpected token `(' ./extract_eod_report_stats_new.sh: line 204: `TRANSACTIONS_RECEIVED_TOP=`grep... (6 Replies)
Discussion started by: Peter.Lovell
6 Replies

4. Shell Programming and Scripting

Bash: renaming file issues.

Hi, i want to rename a group of directories and files of my music, some items are like this: - , for directories. - , for files. I want to do something like this: , for directories. , for files. This is my code: #!/bin/bash for fname in *.mp3; do echo item: $fname mv... (2 Replies)
Discussion started by: josco1982
2 Replies

5. Shell Programming and Scripting

Unix bash script (mv issues);

Hey guys, I've registered here as I need urgent help. This is assignment for school and as you can see below I've completed the work. I'm simply stuck on one area. :wall: This script takes the first parameter (which is to be the new extension) and each parameter after that is a file... (1 Reply)
Discussion started by: Cynosure
1 Replies

6. Shell Programming and Scripting

Bash Script Issues (If statement for file copying)

Writing a bash script for use with Geektool, pulls the battery info, and shuffles images around so that an Image geeklet can display the correct expression as the desktop background. (Eventually I intend to make it more intricate, based on more variables, and add more expressions) I'm extremely... (1 Reply)
Discussion started by: The_Ardly374
1 Replies

7. Shell Programming and Scripting

Bash Case Issues..

Hi, I'm having some trouble with using "case...esac" in Bash. I've googled it and am stuggling to understand the syntax and how to do certain things. Firstly, I want to be able to choose a case based on a variable number For example, I have in my code a place where a user can enter... (2 Replies)
Discussion started by: Ste_Moore01
2 Replies

8. Shell Programming and Scripting

Bash/cron issues

Hi all, I am trying to run a cronjob to push my files to my git repo once a week and output a prompt to a logfile, my script works fine if I invoke it manually but my cronjob wont run for some reason, I have sourced the file, and restarted my Mac to no avail, right now I believe I have the cronjob... (8 Replies)
Discussion started by: gmenfan83
8 Replies

9. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

10. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies
CHECKBASHISMS(1)					      General Commands Manual						  CHECKBASHISMS(1)

NAME
checkbashisms - check for bashisms in /bin/sh scripts SYNOPSIS
checkbashisms script ... checkbashisms --help|--version DESCRIPTION
checkbashisms, based on one of the checks from the lintian system, performs basic checks on /bin/sh shell scripts for the possible presence of bashisms. It takes the names of the shell scripts on the command line, and outputs warnings if possible bashisms are detected. Note that the definition of a bashism in this context roughly equates to "a shell feature that is not required to be supported by POSIX"; this means that some issues flagged may be permitted under optional sections of POSIX, such as XSI or User Portability. In cases where POSIX and Debian Policy disagree, checkbashisms by default allows extensions permitted by Policy but may also provide options for stricter checking. OPTIONS
--help, -h Show a summary of options. --newline, -n Check for "echo -n" usage (non POSIX but required by Debian Policy 10.4.) --posix, -p Check for issues which are non POSIX but required to be supported by Debian Policy 10.4 (implies -n). --force, -f Force each script to be checked, even if it would normally not be (for instance, it has a bash or non POSIX shell shebang or appears to be a shell wrapper). --extra, -x Highlight lines which, whilst they do not contain bashisms, may be useful in determining whether a particular issue is a false posi- tive which may be ignored. For example, the use of "$BASH_ENV" may be preceded by checking whether "$BASH" is set. --version, -v Show version and copyright information. EXIT VALUES
The exit value will be 0 if no possible bashisms or other problems were detected. Otherwise it will be the sum of the following error val- ues: 1 A possible bashism was detected. 2 A file was skipped for some reason, for example, because it was unreadable or not found. The warning message will give details. SEE ALSO
lintian(1). AUTHOR
checkbashisms was originally written as a shell script by Yann Dirson <dirson@debian.org> and rewritten in Perl with many more features by Julian Gilbey <jdg@debian.org>. DEBIAN
Debian Utilities CHECKBASHISMS(1)
All times are GMT -4. The time now is 10:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy