Visit Our UNIX and Linux User Community


Function Issues


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Function Issues
# 1  
Old 10-16-2014
Function Issues

I am converting English letters/words/punctuation in leet speak. My current script works just fine, but when I call the functions it seem to be bypassing my second function altogether. I am new to shell scripting so excuse me if its an easy fix.

Also, when using SED for whole word phrases like 'are' or a punctuation mark like '.' is sed -e still appropriate or should I be using another command like -i (insert)?

Thanks.

Code:
#!/bin/bash

INPUT=$@ 
echo 'Enter String'


standard()
{
sed -e 's/a/4/g' -e 's/b/8/g' -e 's/c/(/g' -e 's/d/|)/g' -e 's/e/3/g' -e 's/f/ph/g' -e 's/g/9/g' -e 's/h/#/g' -e 's/i/!/g' -e 's/j/;/g' -e 's/k/x/g' -e 's/l/1/g' -e 's/m/^^/g' -e 's/n/~/g' -e 's/o/0/g' -e 's/p/|*/g' -e 's/q/0_/g' -e 's/r/|2/g' -e 's/s/5/g' -e 's/t/7/g' -e 's/u/|_|/g' -e 's/v/\//g' -e 's/w/vv/g' -e 's/x/></g' -e 's/y/j/g' -e 's/z/2/g' $INPUT
}


word ()
{
sed -e 's/ee/ea/' $INPUT
}

word
standard;



exit

# 2  
Old 10-16-2014
To me it seems you had simply forgotten the trailing g for sed within the word function Smilie

hth
# 3  
Old 10-16-2014
Sure it's bypassed? Or, as it is called first, could it be overwritten? You are running both functions on the same unmodified input.
# 4  
Old 10-16-2014
Script is fine you need to call the script with file as argument .
sh shell_script.sh input_file
if you wish to get the input conversion, rather using $INPUT at end of sed use echo statement will do the result
read INPUT
echo $INPUT |sed ...
# 5  
Old 10-16-2014
That what I was thinking. Do I need to make another variable? For example, 'input2'. It is definitely overwriting whatever function I call first.

---------- Post updated at 04:15 PM ---------- Previous update was at 04:12 PM ----------

Quote:
Originally Posted by posix
Script is fine you need to call the script with file as argument .
sh shell_script.sh input_file
if you wish to get the input conversion, rather using $INPUT at end of sed use echo statement will do the result
read INPUT
echo $INPUT |sed ...
Thank you I will try this and let you know if it works. I am expecting user input not a file, would that have any effect on the example you provided?

Previous Thread | Next Thread
Test Your Knowledge in Computers #511
Difficulty: Medium
Many programming languages do not allow you to begin a variable name with a number as it would make it more difficult for a compiler or interpreter to parse a program's source code.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies

2. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

3. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

4. Shell Programming and Scripting

Help to Modify File Name in each function before calling another function.

I have a script which does gunzip, zip and untar. Input to the script is file name and file directory (where file is located) I am reading the input parameters as follows: FILENAME=$1 FILEDIR=$2 I have created 3 functions that are as follows: 1) gunzip file 2) unzip file... (2 Replies)
Discussion started by: pinnacle
2 Replies

5. Programming

How to step in one function after the function be executed in gdb?

In gdb, I can call one function with command "call", but how can I step in the function? I don't want to restart the program, but the function had been executed, gdb will execute next statement, and I don't know how to recall the function. (4 Replies)
Discussion started by: 915086731
4 Replies

6. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

7. Programming

performance issues of calling a function in if condition

Hi, I have written a program in C and have to test the return value of the functions. So the normal way of doin this wud b int rc rc=myfunction(input); if(rc=TRUE){ } else{ } But instead of doing this I have called the function in the if() condition. Does this have any... (2 Replies)
Discussion started by: sidmania
2 Replies

8. Shell Programming and Scripting

Return a value from called function to the calling function

I have two scripts. script1.sh looks -------------------------------- #!/bin/bash display() { echo "Welcome to Unix" } display ----------------------------- Script2.sh #!/bin/bash sh script1.sh //simply calling script1.sh ------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies

9. Shell Programming and Scripting

Quit Function Issues

Hi everyone, I am writing a small menu driven program and have come across a problem i am having trouble solving. I am using Windows XP and i am developing this in the Unix Bash shell. I am trying to make it possible to exit the program from each of the five main interfaces. The code is as... (4 Replies)
Discussion started by: warlock129
4 Replies

10. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

Featured Tech Videos