Questions tagged [shell-script]

Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

Filter by
Sorted by
Tagged with
0 votes
0 answers
9 views

Direct output from gnome-terminal to text file

Hi I am trying to direct output of my script to a file My script is gnome-terminal -- ./program +config I have consulted some post and have tried gnome-terminal -- "./program +config 2>&...
0 votes
0 answers
24 views

Bash Script to output various data about a directory? (Directory owner, number of files, name/size of biggest file) [duplicate]

I am still very new to Linux, and I am tasked with writing a bash script that outputs various details inside a menu box. These details include: Directory owner/permissions, Number of files in ...
  • 11
0 votes
0 answers
18 views

Autoselection for gmx trjcat using bash shell

I would like to auto select c for continue for gmx trjcat. The following command was used: echo 'c c c c c' | gmx trjcat -f trajectory1.xtc trajectory2.xtc trajectory3.xtc trajectory4.xtc trajectory5....
0 votes
2 answers
12 views

Selectively extracting files of gzipped archives into new directories whose names are derived from the archive's filename

I've got a folder with thousands of gzipped archive files that contain several XML files. Now I need a script that loops over all archive files and selectively extracts a file with a certain filename (...
  • 117
0 votes
0 answers
36 views

Where should I put my personal shell script in terms of safety?

I am learning sh to make some customized function. I am looking for a safety location for the personal script, since I check from stack exchange, some say that put personal script under ~/bin may ...
-1 votes
0 answers
28 views

how to process reading a file and extracting values

I have file (yaml): env: - name: dev repo: dev scope: - scope1 - scope2 - name: prod repo: prod scope: - scope2 - scope3 I would like to process the file and extract ...
  • 99
-7 votes
1 answer
55 views

Difference between ' and ` in bash script

Could you please explain what difference between a backtick (') and a single quotation mark (') in bash programming?
0 votes
0 answers
25 views

How to handle hyphen/dash (-) character with echo or printf? [duplicate]

I'm doing some Linux Shell exercises in Hacker Rank. One of the problems is to take a text file containing N lines of ASCII characters and print out only the 3rd charater in each line. I came up with: ...
-2 votes
1 answer
63 views

shell script running inside devcontainer Syntax error: "(" unexpected

the below test.sh running in windows command prompt working as expected. however when running inside devcontainer it got failed files=( "first" "second" ) for i in &...
-4 votes
0 answers
29 views

set command in shell script is stuck [closed]

#!/bin/bash -f echo "inside script.sh" set filepath=/scratch/username/readfilepath.txt set filepathstr=`awk '/Lt/ {print}' $filepath` echo $filepathstr When i am running the command from ...
-5 votes
1 answer
61 views

printing prime number in bash [closed]

hi i am new to programming and currnetly learing bash script. please help with this error " line 28: expected `)' " Given below is my program. read -p "enter the number:" a while [...
0 votes
1 answer
33 views

Using a variable in between ' 's

I have a bash script with a line that was originally this convert '%d.jpg[1-300]' combined.pdf Uses convert from Imagemagick to strap a load of sequentially numbered jpgs in to a PDF. I've written a ...
1 vote
1 answer
56 views

How to test response of a Python script on one line?

Following an example I have been provided, I'm reading a result from another script to determine course of action. isOK=$(somepythonscript.py --someParametersHere) if [ "$isOK" = true ]; ...
1 vote
1 answer
171 views

How can I collapse three statements into one?

I need to create an .sh script, which is a new thing for me. I have some examples to follow but I'm hoping to do better. I see something like this: date -d $date | grep "Fri" $status=$? if [ ...
1 vote
0 answers
36 views

How does the system decide which shell runs a script without a shebang line? [duplicate]

I have this "script" on my Arch Linux system: $ cat ~/scripts/foo.sh ps -hp $$ It will simply run ps on its own PID. But the script has no shebang line. I was expecting that in the absence ...
  • 228k
1 vote
2 answers
75 views

Is it possible to make an alias for !:0 , or is there an alternative?

Being truthful, I find the shortcut !:0 not being short enough, considering it also requires the shift key. I was wondering if I can make an alias or function for it, I'm aware I'm missing something. ...
  • 2,669
2 votes
2 answers
71 views

How can I assign values from text to variables?

I have this text: node1: connect command: ssh user@123.23.23.23 password: qcipunbnctza node2: connect command: ssh user@123.23.23.44 password: ejrpnnwsczpa node3: connect command: ssh user@123.23.23....
  • 23
0 votes
1 answer
17 views

rtorrent scripting help

rtorrent provides a nice script for moving downloads to a directory based on label or name https://rtorrent-docs.readthedocs.io/en/latest/use-cases.html#versatile-move i'm trying to configure the ...
  • 101
0 votes
1 answer
47 views

Running Commands on files sequentially

I'm trying to figure out how to write a script that will run a command on files in a directory sequentially with a pause for each command to wait to complete. Here's an example. cat >> text.txt ...
  • 103
0 votes
2 answers
80 views

Dangers of executable file with '#' in name?

This might be a FAQ--happy to have the question closed if it's a dupe--but I'm not sure how to find it if so. I'd also be happy with an answer that simply told me how to find the relevant ...
  • 103
-5 votes
0 answers
36 views

Remove target file from target directory [closed]

Remove target file from the target directory target file name : bangalore.txt target directory : /home/thor/asia/
-3 votes
2 answers
55 views

Bash Script - Expand ESCAPED dollar-sign ($) into its Variable

My Problem I have this run.sh script: #!/bin/bash TODAY=$(date) FILE="my_file.txt.\${TODAY}" When I echo FILE I get this: echo ${FILE} Output: `my_file.txt.${TODAY}` But I want this: ...
-4 votes
3 answers
67 views

Print odd numbered lines, starting with the first line

I want to write a bash script than prints only odd lines of file, including the first line without used sed or awk, also without &&, || and ;
3 votes
1 answer
46 views

tar files with backslahes on Debian

I need to copy files that contain (Windows-style) backslahes from a Debian 10 pod. I'm having trouble with GNU tar 1.30 archiving files with backslashes: docker run --rm -it debian:10 bash inside the ...
  • 133
-2 votes
0 answers
34 views

concatenate columns with variable and text

so I have a path variable: $in_path="/path/to/files" and a file list metadata.csv which looks like this: header.1 header.2 other.1 other.2 other.n run1 file1 a 1 q run1 file2 b 3 r run2 ...
  • 1
0 votes
0 answers
29 views

Unbound variable when passing to npx

I'm trying to create a simple script in my package.json file of my node project { "scripts": { "db:create-migration": "echo 'Enter a filename' && read name &&...
0 votes
0 answers
40 views

Need help in bash script to auto increment the value of tags

I have written a simple bash script for adding tags while launching new servers. #!/bin/bash instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) aws ec2 create-tags --resources $...
1 vote
1 answer
36 views

Executing commands with incrementing filename with pause in between

I have files with numerical incrementing suffixes in filename filename01 filename02 . . . filename250 I want to be able to execute commands that can pause before the next cat command is executed cat ...
  • 13
0 votes
2 answers
79 views

Expand variable in the JSON payload of a curl command

I have a shell script that sends a post request with curl. #!/bin/sh NEXT_JOB_COMMANDS='["sleep", "200s"]' STATUS="successful" if [ "$STATUS" = "...
1 vote
1 answer
24 views

How to retrieve the exit-code from a transient systemd unit using the gdbus utility

From within a Docker container I'm able to create a transient systemd unit in the host Linux OS to run a script. The script returns exit 0 on success, exit 1 on failure. The script below creates the ...
4 votes
2 answers
785 views

I need to have each line of a file run in a subshell of its own

I have a script that works fine, but runs in series. I would like to have the script take each line from a text file and run/spawn that line in a subshell and then move onto the next line and so on. I ...
0 votes
1 answer
43 views

Moves files with the same name to a directory and writes the counted number to the directory name

find /volume1/file/* -type f \( -name "*DF*" -a -name "*LIVE*" \) -print0 | while IFS= read -d '' file do # extract the name of the directory to create dirName="${file%...
0 votes
0 answers
51 views

Replace a string in a column of a text file based on matching string listed in another file

Following my previous question I have multiple set of file, so I greped on list and wanted to change other file by using grep file.txt for example I am pasting three file here File 1 chr - seq1 ...
  • 17
0 votes
3 answers
71 views

Sorting number ranges from two arrays in bash

I have two arrays with the same number of elements I want to manipulate. They are read from a file into two arrays (odd numbered lines go into array one, even numbered into array 2): arr1=("1&...
  • 1
-2 votes
2 answers
53 views

Renaming object or element in perticular range in a column of text file

To expand on my previous question, I have another pattern of a file, I am trying to change the name of first column ranging from seq1 to seq20 (seq1-seq20) as seq1 similarly ranging from seq21 to ...
  • 17
2 votes
1 answer
130 views

How to read constant size buffers from a named pipe, and run a command for each buffer

There is a function in terminal: redis-cli -x PUBLISH myChannel. It reads data from stdin and does its job. FIFO itself doesn't give chunked data. So I need to create chunks from the stream, and run ...
0 votes
0 answers
27 views

Script for awscli check not working with crontab schedule

I have written a small code snippet to check the aws cli version #!/usr/bin/env bash if [ -e "/usr/local/bin/aws" ]; then myAWS="/usr/local/bin/aws" else ...
-2 votes
0 answers
50 views

How to write a shell script to create the network configuration file

How can I create the below configuration file using shell script which the file should be created automatically using the script. By getting the input from the user. The path which the file to be ...
  • 1
0 votes
1 answer
18 views

Systemd service start cannot find command in starter script

I have a program that I want to run as a daemon, let's call it dummy. I have to parse params for it, so I need a starter script, a config file and the program itself as well as it's dependencies, ...
1 vote
1 answer
87 views

bash if-else statement not working as expected

I have a script in which I check the execution codes (0 assign to SUCCESS and 1 assign to FAILURE). I am using a if-else statement to check whether the execution code is 0 or 1. If it is 0 I want to ...
2 votes
1 answer
36 views

How to read hourly files of a day and merge it?

I have a folder of Netcdf files. These files are six hourly wind files for a month. I want to combine all the files. I don't know how to make a shell script to read the files in order of hour to ...
0 votes
1 answer
46 views

How to manually develop a UUID without using uuidgen?

For an assessment we have been asked to generate two different versions of UUID without the use of built-in UUID generators, I can't find any information on how to do that, i only know uuidgen and ...
0 votes
1 answer
28 views

Bash variable with :

I am new to bash and am trying to understand a script I have been passed. Within the script, I have the following variable: site_source="${site_host[$i]}:public_html" Can anyone confirm ...
  • 271
0 votes
0 answers
23 views

Ubuntu LTS 22.04.01 How to make a master script execute multiple other scripts, but opening a new terminal for each process

Background info: I am hosting multiple Minecraft servers, and am updating the servers frequently. I am currently launching by opening a terminal window, then issuing a screen command in each window. ...
-1 votes
1 answer
54 views

Remove duplicate lines without sorting and ignore case

So, let's say I want to remove duplicate lines without sorting, as in this thread, but I also want to remove duplicate lines that aren't case sensitive without converting all the strings to uppercase ...
0 votes
1 answer
47 views

Why isn't my systemd timer executing my sh script?

My youtube.sh file located in /home/deck/Desktop/youtube.sh: #1/bin/env bash pactl -- set-sink-volume 0 100% xdg-open A youtube video link My youtube.timer file located in /etc/systemd/system/youtube....
0 votes
2 answers
66 views

Is it bad practice to use sed to pass a variable through to another script?

There are two shell scripts. One of which is a source file source.sh. This source file will exist for multiple people each with their own directories. name = "foo" The main script main.sh ...
  • 3
10 votes
1 answer
847 views

Use the 'cp' command in a Bash script and exclude a specific directory

I need to run this command in a shell script to copy source > destination and exclude a folder. No rsync, tar, find, mv, etc. Exactly this command: cp -var test/!(test2) testbkp In the shell it ...
4 votes
4 answers
467 views

Generating JSON in a shell script

I need to generate JSON output as below: [{ "Service": "service1-name", "AWS Account": "service1-dev", "AD Accounts": { "APP-...
-2 votes
0 answers
22 views

Shell script for GSAM connectivity check produces syntax error near unexpected token "then"

#!/bin/bash #Define input csv file path CSV_FILE="file_name or path" #Loop through each line in the csv file while IFS=',' read -r GSAM PORT EMAIL do #Attempt to connect to gsam server ...

1
2 3 4 5
320