Ubuntu shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ubuntu shell script
# 1  
Old 05-27-2008
Ubuntu shell script

I got the below script on line but can't seem to get it to work as there are syntax errors where 'len' is shown. Can anyone help with this??

echo " Enter the String"
read str
echo $str > str.txt
len = 'echo $str | wc -c'
len = 'expr $len -1'
c= 0 , w = 0 , s = 0 , i = 1
echo " Length of string = $len"
w = 'echo $str | wc - w'
c = 'echo $str | wc -c'
while [ i -le $ len ]
do
st = 'cut - c$I str.txt'
if ["str" = " "] then
s = 'expr $s + 1'
fi
i = 'expr $i + 1
done
echo "Character = $c"
echo "Words = $w"
echo "Spaces = $s"
# 2  
Old 05-27-2008
Welcome to unix.com forum.
i) Please read the forum rules before posting, and don't post homework's.
ii) use code tags when you post your script
iii) this is a shell script

Here is your script corrected.

Code:
#!/bin/sh
echo " Enter the String"
read str
echo $str > str.txt
len=`echo "$str" | wc -c`
len=`expr $len - 1`
s=0 ; i=1;
echo "Length of string = $len"
w=`echo "$str" | wc -w`
c=`echo "$str" | wc -c`
while [ $i -le $len ]
do
   str=`cut -c $i str.txt`
     if [ -z $str ]; then
       s=`expr $s + 1`
     fi
   i=`expr $i + 1`
done
echo "Character = $(( c - 1 ))"
echo "Words = $w"
echo "Spaces = $s"


Last edited by danmero; 05-27-2008 at 10:53 AM.. Reason: add color's
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to start a Shell Script in a VirtualBox(Ubuntu)?

Hi,so today is my first day with linux. I have some scripts from a friend and now im trying to run them but it doesnt work. So what i tried is: -Moved the scripts to a specific directoy (into my document folder) -then i opened the standard terminal in ubuntu (GNOME-Terminal) -i typed in "Ls",... (3 Replies)
Discussion started by: easy123
3 Replies

2. Shell Programming and Scripting

Red Hat and Ubuntu shell scripting

Are basic scripts in awk or bash or perl or other shell scripting languages the same in RHEL red hat as ubuntu? (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Shell Programming and Scripting

How can draw line on Ubuntu, shell programming?

https://www.unix.com/attachment.php?attachmentid=6304&d=1432179166 how can draw line like this? on ubuntu, shell programming. i tried "-" , " l " but it's failed.. (2 Replies)
Discussion started by: gotit
2 Replies

4. Ubuntu

best books to begin shell scripting in ubuntu

pleas suggest free e books to begin Bash scripting in ubuntu..... (2 Replies)
Discussion started by: vyom
2 Replies

5. UNIX for Dummies Questions & Answers

terminator shell not working after upgrading ubuntu linux

Terminator is a program that allows users to set up flexible arrangements of GNOME terminals. It has stopped working for me after upgrading to ubuntu 11.10. it does not give prompt to type anything. Just stuck with /bin/bash in the title. I removed and installed again, same... (2 Replies)
Discussion started by: analyst
2 Replies

6. Ubuntu

Ubuntu 12.04 Using Gnome Shell NM Applet Issues

I think it may be a bug: This is the scenario: I installed a barebones Ubuntu 12.04 using GNOME-SHELL on a usbstick(work related project). All worked fine from the laptop that I did the installation from. It grabbed an ip address automatically assigning the nic (eth0) and the wireless... (1 Reply)
Discussion started by: metallica1973
1 Replies

7. Ubuntu

Ubuntu 12.04 using gnome-shell

Ubuntu 12.04 using gnome-shell I just removed the entire unity unity-2d gnome desktop and installed the barebones essentials "gnome-shell" and all is working fine. The problem that I have noticed seems to be with permissions. These are the things that I cannot do: 1 -(tty access) ... (1 Reply)
Discussion started by: metallica1973
1 Replies

8. Programming

writing a shell program in ubuntu

Hi all, I have an assignment from school to write a shell program in linux. the idea is to exercise fork() and execv() functions.. the shell program is supposed to be the master and every command that the user prints will run in a new process. we also need to try running the command in every... (1 Reply)
Discussion started by: r3vive
1 Replies

9. Shell Programming and Scripting

Change of shell in ubuntu

Hi all, I am facing a situation here.. My default shell is BASH. I have to change my shell from bash to ksh in ubuntu.. I have used chsh -s /bin/ksh. It doesn't work. Is there any way to set or configure it..? Please advice...:confused: (4 Replies)
Discussion started by: jdash.ps
4 Replies

10. Shell Programming and Scripting

Chek if a file exists in Ubuntu and Cent OS using shell script

I have tried few examples in the internet but all of them are different and none worked. I need to check if a file exists in a directory if it does not then exit . here is what I have for now $filename ="/usr/local/net/var/lib/directoryservice/sync.disable" if ; then echo "The file exists"... (2 Replies)
Discussion started by: m_kk
2 Replies
Login or Register to Ask a Question