Question:
How to take a whole line as argument In bash script?

In a Bash script, you can take a whole line as an argument by using the special variable space “ , “ and you can set the default seperator to “ \n ” with IFS=$'\n' when you want do seperate by line.

Let suppose you have a file ‘zz’

wire [3:0] dcs_ctrl


And you wnat to print this file like this

wire [3:0] dcs_ctrl0

wire [3:0] dcs_ctrl1

wire [3:0] dcs_ctrl2

wire [3:0] dcs_ctrl3


For this, you have to do the operation for the whole line manually (like print the whole line 4 times as following).

for i in `cat zz`; do for j in {0..3}; do echo "$i"; done; done


However, using the default seperator in bash is space  , and you can set the default seperator to \n with IFS=$'\n', you can separately do it using the below code

$ cat zz

wire [3:0] dcs_ctrl


$ IFS=$'\n'; for i in `cat zz`; do for j in {0..3}; do echo "$i"; done; done

wire [3:0] dcs_ctrl

wire [3:0] dcs_ctrl

wire [3:0] dcs_ctrl

wire [3:0] dcs_ctrl


Answered by: >LF-DevJourney

Credit:> StackOverflow


Suggested blogs:

>How to do wild grouping of friends in Python?

>How to download an entire S3 bucket - Complete Guide

>How to get item details of Woo Commerce in custom email content?

>How to install Laravel using composer and configure?

>How to merge cells with HTML, CSS, and PHP?

>How to Migrate your apps to Android 13

>How to Read a csv file with php using cURL

>How to read frame from ffmpeg subprocess in Python?


Submit
0 Answers

What Our Clients Say About Us

Client satisfaction is our ultimate goal. Here are some kind words of our precious clients they have used to express their satisfaction with our service.

Why Choose Us ?

We endow businesses with flexible engagement models based on their unique needs. Our strength lies in state-of-the-art technology and affordable consulting services. Try us for fast POCs, full-fledged applications, or technology consulting. Always available for your service.