LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-12-2008, 04:11 PM   #1
vega2k
LQ Newbie
 
Registered: Oct 2007
Location: 127.0.0.1
Distribution: Ubuntu 7.10, Debian 4.0
Posts: 13

Rep: Reputation: 0
Help with a shell script


Hello,
I need some help with a shell script and hope you could help me.

I want the script to take the input(text string) and then print it out but remove the first character every time until only there is 10 characters left in the text string.

Ex.
Text input: just a random input
Printed:
ust a random input
st a random input
t a random input
a random input
a random input
random input
random input
andom input
ndom input
 
Old 07-12-2008, 04:36 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Sounds very much like homework to me ...
 
Old 07-12-2008, 09:02 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by vega2k View Post
Hello,
I need some help with a shell script and hope you could help me.

I want the script to take the input(text string) and then print it out but remove the first character every time until only there is 10 characters left in the text string.

Ex.
Text input: just a random input
Printed:
ust a random input
st a random input
t a random input
a random input
a random input
random input
random input
andom input
ndom input
its definitely homework to me. however, i will just guide you to a start. To cut strings, look here under substring extraction, or man cut.
You most certainly need a loop, so see here for how to construct a loop. You may also need a character count of the whole string as a counter. man wc for that
 
Old 07-13-2008, 09:52 AM   #4
vega2k
LQ Newbie
 
Registered: Oct 2007
Location: 127.0.0.1
Distribution: Ubuntu 7.10, Debian 4.0
Posts: 13

Original Poster
Rep: Reputation: 0
It's not homework but I can really agree with you that it look like that. (I've had a *nix class long ago doesn't rember much tought)
I've tried to figuring it out my self but I cant rember how to do it.
Something like this, going to look at ghostdog74 later and se if I can solve it. Thanks for for it btw it cant do more then help me. ^^

$in="just a random input";
$i="wc -c `$in`";
while [$i <= 10 ] do
echo $in | -w`$i`-;
$i++;
done
 
Old 07-13-2008, 02:34 PM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Hint: sed.
 
Old 07-15-2008, 07:41 AM   #6
jcookeman
Member
 
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
Code:
#!/usr/bin/env bash
read -p "Enter random string: " STRING
while [ "${#STRING}" -gt "10" ]
do
     STRING=${STRING#?}
     echo $STRING
done
exit 0
 
  


Reply

Tags
removal



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
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 06:24 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
I made a shortcut to a shell script and it is using default shell icon... shlinux Linux - Software 2 04-20-2006 06:29 AM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:23 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
Open Source Consulting | Domain Registration