LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-22-2021, 05:44 PM   #1
skiende74
LQ Newbie
 
Registered: Jun 2021
Posts: 2

Rep: Reputation: Disabled
Simple question about shell script


I want to do base64 encoding of some string 500 times repeatedly.
So I tried to use for loop, but I'm in trouble.

How do I save the result of base64 operation into variable?
I tried to this, but It didn't work.

k='string'
for i in $(seq 500)
do
k= (echo $k|base64)
done

The problem is 4th line.
echo $k|base64 do work,but k = echo $k|base64 don't work.
How do I save this operation result into k?

Last edited by skiende74; 06-22-2021 at 05:48 PM.
 
Old 06-22-2021, 06:28 PM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554

See Bash FAQ #2: How can I store the return value and/or output of a command in a variable?

 
Old 06-22-2021, 07:16 PM   #3
skiende74
LQ Newbie
 
Registered: Jun 2021
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks. It solved.
But I reallized that It is too slow, so I think I must use python.

Last edited by skiende74; 06-22-2021 at 07:21 PM.
 
Old 06-23-2021, 02:12 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,927

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
base encoding is slow itself, will not be [much] faster in python. But you can try. You can report back if that was the case.
If you want to speed it up you may need to run them parallel to each other.
 
Old 06-23-2021, 10:28 AM   #5
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
Quote:
Originally Posted by skiende74 View Post
But I reallized that It is too slow
Too slow for what?

Wait... what are you even trying to do here?

Quote:
Originally Posted by skiende74 View Post
I want to do base64 encoding of some string 500 times repeatedly.
Why?

What do you think repeatedly applying base64 five hundred times will achieve?

For every possibility that comes to mind, you're doing it wrong, and the language you use wont change that.

 
  


Reply



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
Simple Slackware vs simple Arch vs simple Frugalware punchy71 Linux - Distributions 2 08-28-2012 02:30 PM
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 05:34 PM
Need help with a simple script shell script WindowBreaker Linux - Software 2 12-15-2005 12:45 PM
simple shell script question mathfeel Linux - General 12 03-06-2003 11:23 AM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:36 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