Read variable line by line in shell (dash included)Check if a directory exists in a shell scriptHow do I prompt for Yes/No/Cancel input in a Linux shell script?Shell command to sum integers, one per line?In the shell, what does “ 2>&1 ” mean?How to count all the lines of code in a directory recursively?How to declare and use boolean variables in shell script?How to concatenate string variables in BashDelete lines in a text file that contain a specific stringCheck existence of input argument in a Bash shell scriptHow to read a file into a variable in shell?

What does $!# mean in Shell scripting?

Can I connect my older mathematica front-end to the free wolfram engine?

Ethical issue - how can I better document what is happening?

Can a person survive on blood in place of water?

Can a British citizen living in France vote in both France and Britain in the European Elections?

Is it possible to remotely hack the GPS system and disable GPS service worldwide?

NIntegrate doesn't evaluate

What is a fully qualified name?

Is Jon Snow the last of his House?

Ingress filtering on edge routers and performance concerns

How to ignore kerning of underbrace in math mode

Why did Jon Snow do this immoral act if he is so honorable?

Can I summon an otherworldly creature with the Gate spell without knowing its true name?

Apt - strange requests to d16r8ew072anqo.cloudfront.net:80

Why does Mjolnir fall down in Age of Ultron but not in Endgame?

Does this strict reading of the rules allow both Extra Attack and the Thirsting Blade warlock invocation to be used together?

Can my floppy disk still work without a shutter spring?

Is it truly impossible to tell what a CPU is doing?

Did this character show any indication of wanting to rule before S8E6?

Have 1.5% of all nuclear reactors ever built melted down?

How to let other coworkers know that I don't share my coworker's political views?

Where's this lookout in Nova Scotia?

Count Even Digits In Number

Why do Russians almost not use verbs of possession akin to "have"?



Read variable line by line in shell (dash included)


Check if a directory exists in a shell scriptHow do I prompt for Yes/No/Cancel input in a Linux shell script?Shell command to sum integers, one per line?In the shell, what does “ 2>&1 ” mean?How to count all the lines of code in a directory recursively?How to declare and use boolean variables in shell script?How to concatenate string variables in BashDelete lines in a text file that contain a specific stringCheck existence of input argument in a Bash shell scriptHow to read a file into a variable in shell?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















i have a variable with stored logs. What i want is to read every line of the variable containing logs and keep that line or remove base on some filtering stuffs.



The problem is that my code is working on bash, but not working on dash.



this is my code:



filtered_logs=""
while IFS= read -r line
do
...(store line to $filterered_logs if it comes throught filter )
done <<< "$logs"
logs="$filtered_logs"


this code is working in bash. But ' done <<< "$logs" ' is not working in dash (since is default sh in ubuntu). It's a homework and i need, that it works on every shell possible.



What i tried was:



filtered_logs=""
echo "$logs" |
while IFS= read -r line
do
...(store line to $filterered_logs if it comes throught filter )
done
logs="$filtered_logs"


But if i store something in from while cycle to $filtered_logs, it's not working. And i can't access this while cycle with my debugger too. (I think that the whole while cycle is whole new process since i run it with |.



My question is how to make it works, please. Thank you










share|improve this question






















  • man echo ; man cat ; google "shell input redirection"

    – jhnc
    Mar 24 at 2:34











  • Every shell possible seems a to an unlimited assignment. Do you need to use the while-construction or can you switch to awk, sed or another tool avoiding while (which has more problems like performance and skipping the last line when it is not ending with a newline) ?

    – Walter A
    Mar 24 at 11:16











  • yes, i can use both awk and sed. And it seems that other classmates used that. Sadly i didn't learned how to work with that, so i ended with this.

    – Ruuza
    Mar 24 at 12:16

















0















i have a variable with stored logs. What i want is to read every line of the variable containing logs and keep that line or remove base on some filtering stuffs.



The problem is that my code is working on bash, but not working on dash.



this is my code:



filtered_logs=""
while IFS= read -r line
do
...(store line to $filterered_logs if it comes throught filter )
done <<< "$logs"
logs="$filtered_logs"


this code is working in bash. But ' done <<< "$logs" ' is not working in dash (since is default sh in ubuntu). It's a homework and i need, that it works on every shell possible.



What i tried was:



filtered_logs=""
echo "$logs" |
while IFS= read -r line
do
...(store line to $filterered_logs if it comes throught filter )
done
logs="$filtered_logs"


But if i store something in from while cycle to $filtered_logs, it's not working. And i can't access this while cycle with my debugger too. (I think that the whole while cycle is whole new process since i run it with |.



My question is how to make it works, please. Thank you










share|improve this question






















  • man echo ; man cat ; google "shell input redirection"

    – jhnc
    Mar 24 at 2:34











  • Every shell possible seems a to an unlimited assignment. Do you need to use the while-construction or can you switch to awk, sed or another tool avoiding while (which has more problems like performance and skipping the last line when it is not ending with a newline) ?

    – Walter A
    Mar 24 at 11:16











  • yes, i can use both awk and sed. And it seems that other classmates used that. Sadly i didn't learned how to work with that, so i ended with this.

    – Ruuza
    Mar 24 at 12:16













0












0








0








i have a variable with stored logs. What i want is to read every line of the variable containing logs and keep that line or remove base on some filtering stuffs.



The problem is that my code is working on bash, but not working on dash.



this is my code:



filtered_logs=""
while IFS= read -r line
do
...(store line to $filterered_logs if it comes throught filter )
done <<< "$logs"
logs="$filtered_logs"


this code is working in bash. But ' done <<< "$logs" ' is not working in dash (since is default sh in ubuntu). It's a homework and i need, that it works on every shell possible.



What i tried was:



filtered_logs=""
echo "$logs" |
while IFS= read -r line
do
...(store line to $filterered_logs if it comes throught filter )
done
logs="$filtered_logs"


But if i store something in from while cycle to $filtered_logs, it's not working. And i can't access this while cycle with my debugger too. (I think that the whole while cycle is whole new process since i run it with |.



My question is how to make it works, please. Thank you










share|improve this question














i have a variable with stored logs. What i want is to read every line of the variable containing logs and keep that line or remove base on some filtering stuffs.



The problem is that my code is working on bash, but not working on dash.



this is my code:



filtered_logs=""
while IFS= read -r line
do
...(store line to $filterered_logs if it comes throught filter )
done <<< "$logs"
logs="$filtered_logs"


this code is working in bash. But ' done <<< "$logs" ' is not working in dash (since is default sh in ubuntu). It's a homework and i need, that it works on every shell possible.



What i tried was:



filtered_logs=""
echo "$logs" |
while IFS= read -r line
do
...(store line to $filterered_logs if it comes throught filter )
done
logs="$filtered_logs"


But if i store something in from while cycle to $filtered_logs, it's not working. And i can't access this while cycle with my debugger too. (I think that the whole while cycle is whole new process since i run it with |.



My question is how to make it works, please. Thank you







shell sh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 2:07









RuuzaRuuza

32




32












  • man echo ; man cat ; google "shell input redirection"

    – jhnc
    Mar 24 at 2:34











  • Every shell possible seems a to an unlimited assignment. Do you need to use the while-construction or can you switch to awk, sed or another tool avoiding while (which has more problems like performance and skipping the last line when it is not ending with a newline) ?

    – Walter A
    Mar 24 at 11:16











  • yes, i can use both awk and sed. And it seems that other classmates used that. Sadly i didn't learned how to work with that, so i ended with this.

    – Ruuza
    Mar 24 at 12:16

















  • man echo ; man cat ; google "shell input redirection"

    – jhnc
    Mar 24 at 2:34











  • Every shell possible seems a to an unlimited assignment. Do you need to use the while-construction or can you switch to awk, sed or another tool avoiding while (which has more problems like performance and skipping the last line when it is not ending with a newline) ?

    – Walter A
    Mar 24 at 11:16











  • yes, i can use both awk and sed. And it seems that other classmates used that. Sadly i didn't learned how to work with that, so i ended with this.

    – Ruuza
    Mar 24 at 12:16
















man echo ; man cat ; google "shell input redirection"

– jhnc
Mar 24 at 2:34





man echo ; man cat ; google "shell input redirection"

– jhnc
Mar 24 at 2:34













Every shell possible seems a to an unlimited assignment. Do you need to use the while-construction or can you switch to awk, sed or another tool avoiding while (which has more problems like performance and skipping the last line when it is not ending with a newline) ?

– Walter A
Mar 24 at 11:16





Every shell possible seems a to an unlimited assignment. Do you need to use the while-construction or can you switch to awk, sed or another tool avoiding while (which has more problems like performance and skipping the last line when it is not ending with a newline) ?

– Walter A
Mar 24 at 11:16













yes, i can use both awk and sed. And it seems that other classmates used that. Sadly i didn't learned how to work with that, so i ended with this.

– Ruuza
Mar 24 at 12:16





yes, i can use both awk and sed. And it seems that other classmates used that. Sadly i didn't learned how to work with that, so i ended with this.

– Ruuza
Mar 24 at 12:16












1 Answer
1






active

oldest

votes


















0














It's easy to use clean posix api in your case:



logs=$(
printf "%s" "$logs" |
while IFS= read -r line
do
echo "store this to logs"
done
)





share|improve this answer























  • printf "%s" "$(echo "$logs" | tail -3)" will show that the last newline is missing.

    – Walter A
    Mar 24 at 10:24











  • Thank you so much, it works!. Yes, the last line is missing. I append a newline to variable as workaround. Do you know about better solution?

    – Ruuza
    Mar 24 at 14:08











  • Just printf "%sn" "$logs" or while ....; do ... done <<<"$logs".

    – Kamil Cuk
    Mar 24 at 20:42











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320122%2fread-variable-line-by-line-in-shell-dash-included%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














It's easy to use clean posix api in your case:



logs=$(
printf "%s" "$logs" |
while IFS= read -r line
do
echo "store this to logs"
done
)





share|improve this answer























  • printf "%s" "$(echo "$logs" | tail -3)" will show that the last newline is missing.

    – Walter A
    Mar 24 at 10:24











  • Thank you so much, it works!. Yes, the last line is missing. I append a newline to variable as workaround. Do you know about better solution?

    – Ruuza
    Mar 24 at 14:08











  • Just printf "%sn" "$logs" or while ....; do ... done <<<"$logs".

    – Kamil Cuk
    Mar 24 at 20:42















0














It's easy to use clean posix api in your case:



logs=$(
printf "%s" "$logs" |
while IFS= read -r line
do
echo "store this to logs"
done
)





share|improve this answer























  • printf "%s" "$(echo "$logs" | tail -3)" will show that the last newline is missing.

    – Walter A
    Mar 24 at 10:24











  • Thank you so much, it works!. Yes, the last line is missing. I append a newline to variable as workaround. Do you know about better solution?

    – Ruuza
    Mar 24 at 14:08











  • Just printf "%sn" "$logs" or while ....; do ... done <<<"$logs".

    – Kamil Cuk
    Mar 24 at 20:42













0












0








0







It's easy to use clean posix api in your case:



logs=$(
printf "%s" "$logs" |
while IFS= read -r line
do
echo "store this to logs"
done
)





share|improve this answer













It's easy to use clean posix api in your case:



logs=$(
printf "%s" "$logs" |
while IFS= read -r line
do
echo "store this to logs"
done
)






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 24 at 3:23









Kamil CukKamil Cuk

15.3k2633




15.3k2633












  • printf "%s" "$(echo "$logs" | tail -3)" will show that the last newline is missing.

    – Walter A
    Mar 24 at 10:24











  • Thank you so much, it works!. Yes, the last line is missing. I append a newline to variable as workaround. Do you know about better solution?

    – Ruuza
    Mar 24 at 14:08











  • Just printf "%sn" "$logs" or while ....; do ... done <<<"$logs".

    – Kamil Cuk
    Mar 24 at 20:42

















  • printf "%s" "$(echo "$logs" | tail -3)" will show that the last newline is missing.

    – Walter A
    Mar 24 at 10:24











  • Thank you so much, it works!. Yes, the last line is missing. I append a newline to variable as workaround. Do you know about better solution?

    – Ruuza
    Mar 24 at 14:08











  • Just printf "%sn" "$logs" or while ....; do ... done <<<"$logs".

    – Kamil Cuk
    Mar 24 at 20:42
















printf "%s" "$(echo "$logs" | tail -3)" will show that the last newline is missing.

– Walter A
Mar 24 at 10:24





printf "%s" "$(echo "$logs" | tail -3)" will show that the last newline is missing.

– Walter A
Mar 24 at 10:24













Thank you so much, it works!. Yes, the last line is missing. I append a newline to variable as workaround. Do you know about better solution?

– Ruuza
Mar 24 at 14:08





Thank you so much, it works!. Yes, the last line is missing. I append a newline to variable as workaround. Do you know about better solution?

– Ruuza
Mar 24 at 14:08













Just printf "%sn" "$logs" or while ....; do ... done <<<"$logs".

– Kamil Cuk
Mar 24 at 20:42





Just printf "%sn" "$logs" or while ....; do ... done <<<"$logs".

– Kamil Cuk
Mar 24 at 20:42



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320122%2fread-variable-line-by-line-in-shell-dash-included%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현