Skip to content

Tag: bash

C: Trying to implement unnamed pipes

I’m trying to make a program that simlutates the terminal’s nameless pipes. For example, if I want to run the command: ls –l | grep ‘10’ would be: ./pipes ls -l – grep ’10’ (I use – instead of |). However, my program doesn’t work because execvp fails (bad adress). Thi…

Validating file records shell script

I have a file with content as follows and want to validate the content as 1.I have entries of rec$NUM and this field should be repeated 7 times only. for example I have rec1.any_attribute this rec1 should come only 7 times in whole file. 2.I need validating script for this. If records for rec$NUM are less tha…

how to auto complete files names on bash script?

I have a bash shell script that cd to directory according to a variable. After that I press Tab and files don’t appear like in terminal. Ex: on read code ups, the files don’t appear when I press tab. Answer The read command requires the -e flag in order to use the readline library to edit the comm…

Bash script unexpected result for while loop

I have following bash script to stop Apache server. I am not getting error but an unexpected result. I got the following answer which I do not expect to be, with an infinite printing: I expect to print: Could anybody please tell me what is happening? Answer This doesn’t work the way you seem to think it…

Linux bash printf format with color assign to variable

I just want a String (including coloring) be formatted by printf command and assign the result to a variable. Without assigning it to a variable it works fine, but as soon as I assign the result to a variable and write the result, the format is gone. My example: I found several solutions for passing the resul…

How to send a message to another user via Bash

I am writing a shell script, and I need to send a message to the other user. If I write write user1 in trem, and then write the message and use Ctrl + D, the message will send to user1’s trem successfully. But I want to use a .sh file to send the message to user1 automatically, and I encountered

jq in shellscript: parse argument with ‘-‘

Here’s the json I need to parse: And my code to parse is like the following: The problem is this part: I can’t get the value of it and I guess the reason is that I didn’t pass $var correctly? I also tried But it doesn’t work..Maybe the tiny ‘-‘ in the “config-$val&#82…

filter file with specift words linux

I have files in which the first column is an ID, and the second column is an option, like this: and I need to create a files with the IDs depending with the option. It is to say: I try with cat file.txt | grep -w “option” > file_option but the problem is that the files are mutually exclusive, a…