Questions tagged [bash-scripting]

Bash scripting is making scripts in the Bash shell language.

Filter by
Sorted by
Tagged with
0
votes
1answer
31 views

What is awk '{ print $2; }' doing exactly?

I would like to know what is this statement doing exactly, especially the awk part. ps aux | grep 'sidekiq 5' | grep -v grep | awk '{ print $2; }' | xargs kill -${2:-'TERM'} I know the entire ...
0
votes
1answer
16 views

a very simple Perl script needed

I have the following text file G.txt. I need a perl command perl -e ... that would extract all negative entries ending with Kč, so that first line it will be -107,60 and last will be -63,00 I have ...
0
votes
0answers
22 views

bash for Windows 8.1 [closed]

I would like to install bash intended for Linux and connect it with my CMD under windows 8.1 and use it there. Where can I find something like bash.msi ?
-1
votes
0answers
28 views

Bad decrypt: deprecated key derivation used. Using -iter or -pbkdf2 would be better

any can help me with this challenge, say: "Create a "For" loop that encodes the variable "var" 28 times in "base64". The number of characters in the 28th hash is the ...
1
vote
0answers
17 views

Bash: Open new tab in newly opened terminal

I want to open new terminal windows, each with multiple tabs, and while I've managed to open the windows, I'm having trouble with the tabs. What I currently have is: #!/bin/bash # Opens new window, ...
0
votes
0answers
31 views

How do I copy file contents to a variable while using sudo?

I have a file that only has root permissions. I need to copy its contents into a variable in my script, but when I do content=$(sudo cat secretfile.txt) it captures the "last login" ...
0
votes
1answer
23 views

Shell Script : Take filename as an argument and on a standard output display the contents of the file with line number prefixed to it

So, I'm new to shell scripting and I'm trying to write a shell script which takes filename(.txt) as an argument and displays the line number prefixed with each line on a standard output. This is the ...
0
votes
0answers
28 views

Remove any folders and files that are not .txt-files

I’m trying to make a simple script that creates a hidden folder if it doesn’t exist, and wipe any subfolders or files that are not .txt-files in case it exists already. if [ ! -d .hiddenFolder ]; ...
0
votes
1answer
20 views

VPN Email Alert by IP address (Bash Script)

I have an OpenVPN server, when a user connects to the server they are given an IP from 192.168.1.20-25. I want to get an alert when these IP's reply back as well as when they disconnect. So far I can ...
0
votes
1answer
228 views

Why does my bash script not cd correctly?

I'm using Windows Subsystem for Linux, and learning the terminal. I want to open applications on my desktop with the terminal, so I decided to make a bash script to cd to the .exe file and run it. ...
0
votes
0answers
21 views

aria2c failed to make the directory [duplicate]

I am trying to download urls saved in these text files PendingCases01.txt PendingCases03.txt PendingCases02.txt I tried for f in *.txt;do aria2c -i "$f" -d "$f";done Error:...
1
vote
1answer
50 views

Bash not doing word expansion after command substitution

From GNU's Bash Manual Sections 3.5.7: Word Splitting: The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for ...
0
votes
0answers
23 views

Split a file into multiple files based on values from bookkeeper file

I have 2 files, where I need to split File 1 into multiple files of size specified by File 2 contents. Sum of File 2 contents will always be equal to size of file 1. There can be many entries in File ...
0
votes
1answer
22 views

Print the files if exists from different folders with same suffix integer value in shell script

I have two different folders Folder1 Folder2 cmp_data_0.bin decmp_data_0.bin cmp_data_1.bin decmp_data_1.bin cmp_data_89.bin ...
0
votes
1answer
51 views

BASH: List External drives

I am trying to make a script that list all disk on my Mac exluding /dev/disk0 and /dev/disk0 (I only want it to show the external and virtual drives) and the name of the primary partition. Something ...
0
votes
0answers
32 views

How to modify the apktool path

4.1 dirthy, but this version was not official of apktool, and I was having some problems, so I upgraded to version 2.5.0 and official, however I want my apktool folder to be in /usr/share but if I ...
0
votes
1answer
31 views

How do I replace a certain line in /etc/passwd file?

So, I'm trying to make a script that disables the root account by changing the root:x:0:0:root:/root:/bin/bash with root:x:0:0:root:/root:/sbin/nologin. Is there a command that lets me do this? Thanks....
1
vote
1answer
44 views

Bash script that displays time on terminal

I wanted to write a bash script that serves like a greeting and show date and time(in terminal), and I ran into some issues. I've done some digging I solved most of the issues. The one and only issue ...
0
votes
1answer
145 views

Script runs slow processing stdout piped from service

I am using a utility named oscdump which listens on a specified port for OSC messages and prints the messages to stdout. I wish to parse and process these messages in a script however my script runs ...
0
votes
0answers
19 views

Shell script to copy every 512 bytes from a file [duplicate]

I have an input file of size 1040 bytes. I need to copy the first 512 bytes, skip next 8 bytes and copy the next 512 bytes, skip 8 bytes. I am able to copy the first 512 using dd command, but not sure ...
0
votes
1answer
52 views

Copy every 512 bytes and skip next 8 bytes from Input file to a Output file

I have an input file which is always a multiple of 520 bytes . i,e Input file 1- 1040 bytes Input file 2- 5200 bytes I need to copy every 512 bytes from input file and skip the next 8 bytes from ...
0
votes
1answer
52 views

Supress stdout except for echo commands but show stderr

I have put a very large bash script together that installs packages and configures a LAMP stack etc. With any scripting I usually do, I like to tidy it up by using echo commands to let the user ...
0
votes
1answer
13 views

Bash invisible arguments

Okay, I'm trying to do something tricky in bash. I'm writing a front-end method that will decide whether I am doing something like this: aws ecs update-service ... lots of args or aws ecs create-...
0
votes
1answer
22 views

Randomize lines inside a master shell script for every iteration

I have a master script master_script.sh, which has several scripts inside it. Inside Master_script.sh ./script1.sh ./script2.sh ./script3.sh .. .. ./script10.sh I ...
0
votes
0answers
11 views

Bash Script to Take a line of text and print it in reverse order? [duplicate]

I couldn't solve this problem. Can anyone help me out? For example: User input is: I eat rice the output should be: ecir tae I
1
vote
3answers
46 views

How to run a bash script only on directories that have no subdirectories

I would like to process every directory in my parent directory but only on a condition that these directories have no subdirectories in them. Right now I have a following directory structure: Music ...
0
votes
1answer
50 views

sed pattern from file and substitute with new pattern in another file using string variables

I have several files where I have the following patterns: t= 9.90000 2 2 t= 10.00000 1 1 Now, the value of t (for example 100.00000) and also the value of (2 2) is ...
1
vote
1answer
19 views

Misplaced sub-shell in bash

I'm having trouble with an unfortunate mis-feature in bash, illustrated by this function: trying () { res=0; echo $res; cat some_text_file | while read op rpt rec; do res=1; ...
1
vote
0answers
29 views

Bash script whitespace compliant

I have an huge amount of file to organize, they are a JPG files in an absurd folders structure. I need to move all files from its actual position to an organized folder structure, saving its actually ...
0
votes
1answer
26 views

Run cleanup code without affecting $?

I have a function that creates a temp file.I want the function to delete the temp file before it exits, but I want this cleanup to not effect the $? of the last command in the function i.e. function ...
1
vote
1answer
17 views

Match contents of file to directory and delete it

Let's say I ran a command that redirected certain files from a directory into a file. Now i want to delete those files from the directory. How would i accomplish this. I'm thinking that i would maybe ...
0
votes
1answer
27 views

Replace string between 2 wildcard characters in a variable value using bash scripting

I have a variable value "Cash_20200413_US_02.dat" and I want to rename it as "Cash_20200413_US_*.dat". So basically I want to find : a) the last occurence of string "_" ...
1
vote
1answer
160 views

A try to write a batch script to find all the .c files in the current directory and compile them

I was trying to write a make analog in windows, using batch files But I am a noob in batch scripting, here is my try - I am trying to make a batch script which fill find all the .c files in the ...
0
votes
1answer
84 views

how do I run a sudo command and load the environment variables of current logged on user?

I need to run an ssh sudo command. command is as follows: ssh -i keyfile ubuntu@10.65.21.253 'sh -v /opt/dir/script' the script contains the following: sudo -E node some.js the reason I use the -E ...
-2
votes
2answers
171 views

How do I run a sudo command on a remote machine using ssh?

I am trying to remotely run a shell script on an ubuntu host. I can ssh to the machine using me@host just fine. On the remote machine I can run sudo commands without needing to input a password. I can ...
0
votes
2answers
36 views

I want to know what I'm doing wrong with my code

Code removeapp(){ hi=1 while 'expr ${hi] <= $#'; do { c="${c} $(${hi})" hi=' } sudo rm -rf '/applications/$c.app' } This is code to delete any app.The idea is that the $c adds up the ...
0
votes
1answer
52 views

How can the convert command's output be passed/piped instead of saved to a file?

I made a HTML file with images as base64. I started bash-scripting to make a folders images be base64-printed into this html-file. I worked, I share the code: cat html_head.txt > fil.html for i in *...
0
votes
1answer
39 views

What is the TUI (text-based user interface) equivalent of “yes”

What is the TUI (text-based user interface) equivalent of yes or y in CLI (command line interface)? I am writing a Bash script which has the line, sudo apt install -y iptables-persistent When ...
1
vote
1answer
35 views

For loop logic to skip processing files

I wrote the following script in an attempt to try my hand at automation, to automate some common transformations on sets of text files I work with: #!/bin/bash set -e if [ $# -eq 0 ]; then echo "...
0
votes
1answer
70 views

How to make long pipeline work with echos

I wrote the following for loop as part of a larger script that takes text files as arguments, applying several transformations to them: for i; do echo "Filtering out lines with empty columns...&...
0
votes
0answers
49 views

Bash: How can I edit $@?

I'm writing a wrapper for a utility (in bash). I'd like to pass the utility every argument (including separate flags), except for the first one. I feel that I would like to take $@ and trim $1 (the ...
0
votes
2answers
93 views

Is LC_ALL=C destructive?

I have a reasonably large (~15GB) set of text files. These files are essentially simple databases that contain credentials, and the credentials in them often fall outside of the 128-character ASCII ...
1
vote
1answer
19 views

Seeking equivalent wsl.exe command line

The following single command line in a Windows Desktop shortcut Target field will ping an address and timestamp it. C:\Windows\System32\bash.exe -c "ping 1.0.0.1 | while read line; do echo `date` ...
0
votes
1answer
50 views

monitor PID and respawn processes in bash script (simulatord, nc, ping)

For a student environment, I have a simple bash script that runs upon boot up on Ubuntu 18.04 (@reboot in crontab -e). It runs ok (java file starts, netcat starts, pings, and all PIDs are viewable via ...
0
votes
0answers
14 views

bash, script to git add one file and commit

I'm trying to create a script to do this: git add "file" git commit -m "Comment" My idea is to run: gac "file" "Comment" I know I can do something similar but ...
0
votes
0answers
15 views

Remove multiple files using “find” asking yes to every finding

I'm trying to remove multiple write-protected files but i'm struggling answering "yes" to the prompt. The find command is this: find /media/openhabian/pelis -atime +6 \( -type f -iname "...
0
votes
1answer
78 views

How to delete all files except some specific file (for many folders in a directory)? via bash script

So I have a Master folder that contains about 800 sub-folders (eg. 1,2,3...) which contains many files but I want to delete everything else except the file that ends with *tsv. Is there a way to do ...
5
votes
1answer
85 views

How to unzip a file with a hyphen at the beginning of the file name

I have a Zip file with a hyphen at the start of its name, let's say '- stuff.zip' If I need to move or copy the file, this means that I need to use a double-hyphen so that the filename isn't ...
1
vote
1answer
47 views

How do I edit this texconv “IMGtoBC3.bat” file so it “READS FROM & PRESERVES the directory structure when writing the ”resulting" dds files

How do I edit this texconv "IMGtoBC3.bat" file so it "READS FROM & PRESERVES the directory structure when writing the "resulting" dds files? Personally, I have a large ...
0
votes
1answer
136 views

How can I solve the multiple dots issue and overwrite the original file

First question. When converting, I want to get a file in the format artist name - song title.mp3. The problem is that if there are several dots in the title, I will get the artist name.mp3. I use this ...

1
2 3 4 5
17