Linked Questions

288 votes
5 answers
79k views

Is using a while loop to process text generally considered bad practice in POSIX shells? As Stéphane Chazelas pointed out, some of the reasons for not using shell loop are conceptual, reliability, ...
cuonglm's user avatar
  • 158k
23 votes
3 answers
8k views

I was wondering what is the fastest way to run a script , I've been reading that there is a difference in speed between showing the output of the script on the terminal, redirecting it to a file or ...
Kingofkech's user avatar
  • 1,068
15 votes
2 answers
8k views

1 #!/bin/bash 2 # query2.sh 3 4 numbers=(53 8 12 9 784 69 8 7 1) 5 i=4 6 7 echo ${numbers[@]} # <--- this echoes "53 8 12 9 784 69 8 7 1" to stdout. 8 echo ${numbers[i]} # <--- this echoes ...
Anthony Webber's user avatar
3 votes
7 answers
2k views

I am trying to convert string for example string=11111001 to array which I will be able to access by calling respective array index like arr[0]=1, arr[1]=0 I am new to shell scripting and from what I ...
Sneha Patil's user avatar
4 votes
4 answers
6k views

I'm building a function that will calculate the gauge of wire required given amperage, distance(in feet), and allowable voltage drop. I can calculate the "circular mils" given those values and with ...
jesse_b's user avatar
  • 41.6k
12 votes
2 answers
4k views

Hopefully this question is not too generic. I am very new to shell scripting and I come from a computer architecture/non-scripting programming background. I have noticed on the scripts at my work that ...
LinuxLearner's user avatar
6 votes
1 answer
21k views

I have this line: trap 'jobs -p | xargs kill -9' SIGINT SIGTERM EXIT it is repeated in many bash shell scripts I have. What is the best way to share this code? Can I call a bash function perhaps? ...
Alexander Mills's user avatar
4 votes
1 answer
2k views

Can memory be preallocated in bash for arrays of a defined size? I am iteratively adding strings to an array (declared by declare -a arr) in a loop (arr+=("$str")), and am wondering whether ...
user001's user avatar
  • 3,808
0 votes
3 answers
2k views

I have a .CSV file that I need to extract numbers from. Example of file: #File of numbers 1,2,3,4,5 6,7,8,9,10 I want to use awk (or another utility) to extract the first number and second number and ...
Saad's user avatar
  • 101
0 votes
2 answers
2k views

i have two variables (txt and a line number) i want to insert my txt in the x line card=$(shuf -n1 shuffle.txt) i=$(shuf -i1-52 -n1) 'card' is my txt : a card randomly selected in a shuffle 'deck' ...
Larotule's user avatar
1 vote
1 answer
800 views

In what way does the final value of number being assigned by read var number (and we enter 5) and number=5 differ? I was making this for loop: read var number #number=5 factorial=1 i=1 for i in `seq ...
Peter's user avatar
  • 155
0 votes
1 answer
371 views

I came across a problem and have no idea how to find the OPTIMAL solution. I have a list of files that looks like this: file1\0file2\0...fileX\0\0file(x+1)\0 Every name of file is separated by a \0 ...
ogarogar's user avatar
  • 191
0 votes
1 answer
241 views

I'm pretty new to unix and I'm wondering how I would go about writing a word, letter by letter into my program's memory. So for example if my word was "cup", I'd want an array A to have A[0] = 'c', A[...
TonyIsMyName's user avatar