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
1answer
46 views

Cannot declared a function named "in"?

Here's a script that throws a syntax error if and only if the function is named in: in() { echo 0; } line 1: syntax error near unexpected token `in' Why is that so? I cannot give this ...
0
votes
1answer
52 views

A bit of Bash help with my elif logic on my script

So what I have here is part of my script that is used to read the pcie lanes on the boards to help understand what NVMe's are up and running without having to manually check each drive. This works for ...
0
votes
0answers
15 views

my if statement is returning command not found [duplicate]

in my script an if statement returns: line 3: []: command not found the statement: if ["$(pidof -x $(basename $0) -o %PPID)"]; then echo process already running; exit; fi what I tried: ...
0
votes
2answers
36 views

logger command reports I am a user even if running under sudo?

I have a line logger Ok in my script. When I run it from command line with either of ./myscript.sh sudo ./myscript.sh sudo bash ./myscript.sh it writes in log Oct 17 22:32:01 d40688 mysqlf: Ok I.e. ...
-1
votes
1answer
69 views

Bash "$@" does not substitute variable

I am sorry because this probably has been asked, but I cannot google these special characters properly. I have the following script.sh: #!/bin/bash export c=23; "$@" And when I call it ...
-1
votes
1answer
64 views

Check if there exists filename in directory

I have one file contains people name, like Sam Tom Dad Jack I have one directory that contains name.txt or name.zip which file's form is not the same, like Dad.txt Tom.zip Jack.zip How to find sam ...
4
votes
3answers
188 views

How to add noatime to fstab with script?

I want to add noatime to fstab with my bash script that set up my servers. How do this automatically in a safe way for / partition only? In simple terms: How to append ,noatime to the fourth string of ...
1
vote
1answer
44 views

zsh script to rsync multiple files from same remote directory

I'm running Debian Bullseye (if that matters), and I'm writing a zsh script to use rsync to copy multiple files/directories (passed as arguments to the script) from a given remote directory. They're ...
2
votes
4answers
74 views

sed command failing in script with arguments

I am trying to perform a two step string editing: Match for the string "payload". If found, then add some "#if #endif" code as shown in output file. Then copy the line containing &...
1
vote
1answer
37 views

Bash: command substitution with background job

I'm trying to fire and forget a process within a function in bash. I'd this function to return a status corresponding to the fact the process has indeed been fired and retrieve output of the function ...
0
votes
0answers
26 views

export variables in for loop

I have a terraform project with a terraform.tfvars file where I use these variables: customer_id = 20 customer_name = "sd" alpega_api_url = "efs" token_url = "fesf&...
1
vote
2answers
42 views

Increment mountpoint name with awk

I am currently writing a script that makes mounting of LUKS devices easier. In the script I do have a default mountpoint name (data_1), - however, if a mountpoint like that already exists, I want to ...
2
votes
3answers
144 views

Looping through columns

I have a csv file that looks something like this: first_name,surname,email, first_name2,surname2,email2, ....3,.. ....4,... The number of rows in each column are the same. I want to run a command ...
11
votes
10answers
2k views

Is there a method to indicate the last iteration in a loop over lines of an input file?

Suppose I have a file direction with the lines east north south west south-west and using a loop and echo in a shell script I want to generate this output: Direction: east Direction: north Direction:...
4
votes
0answers
46 views

Why does bash $LINENO change inside an inner block in a function?

I'm trying to debug auto completion script located in /usr/share/bash-completion/bash_completion (bash completion package on every distro) I did export PS4='+'$'\t''$LINENO'$'\t # \t for proper ...
0
votes
1answer
54 views

Determine TLS versions supported by curl

How can I check from a Bash script if the curl executable in PATH supports tlsv1.0 or tlsv1.1 or newer? Basically I would like to inform the user if its curl does not support TLS v1.2 and take the ...
0
votes
1answer
36 views

Use file marker with entr

I've the following code on myscript.sh for the purpose of execute function on a file with .md extension when this file is modified: function my_function(){ echo "I\'ve just seen $1" } ...
1
vote
2answers
35 views

mke2fs - answer to an "overwrite" question from a script

I use mke2fs utility to create a file system. If file system already exists, I get a confirmation prompt: ~# mkfs.ext4 /dev/xvdf mke2fs 1.46.2 (28-Feb-2021) /dev/xvdf contains a ext4 file system ...
0
votes
2answers
42 views

List files that match but with any extension

Given a file with path /foo/bar/a.b.c.d.x I would like to be able to find all files matching /foo/bar/a.b.c.d.* with any final extension This is what I have been using thus far findSiblingFiles () { ...
1
vote
1answer
26 views

Make vim highlight shell scripts at first try

I create a lot of shell scripts with VIM. But since they don't have an extension, VIM doesn't highlight the syntax at first try. So I have to write #!/bin/bash and exit VIM and open it again to have ...
0
votes
1answer
46 views

echo > file complains file does not exists

I have a virtual machine running and its root directory mounted to in ./vm I have this script running on the virtual machine: #!/usr/bin/env bash flag=/dir/flag echo "Listening..." while ...
1
vote
1answer
112 views

How to use clipboard-cli on Wayland?

I am using this module gtts-cli for text to speech conversion. more info here-> https://gtts.readthedocs.io/en/latest/cli.html Basic syntax is $ gtts-cli 'hello' --output /tmp/hello.mp3 && ...
0
votes
1answer
30 views

print numerical values from array in shell script

I have a process which is getting launched by two different processes(one is by init and other by lxc container) I am trying to get the pids of the process using process name by command $(pidof $...
1
vote
4answers
62 views

Apply same sed command on multiple text files

I am doing some pre-processing on files. I have 2 text files which contains data in the following format. Text File 1 "Name","Age","Class" "Total Students:",&...
0
votes
0answers
29 views

Running script at dockerfile for node image

I'm trying to run script file at dockerfile to node project. That script is adding themes repos to the core project - where the dockefile is built and running- . But when trying to run the dockerfile ...
0
votes
1answer
65 views

OpenBSD run script on Startup

I was trying to run a .sh script on my OpenBSD machine on startup. I've made the script executable using the chmod +x command. I've also added the script to cron via an entry reading @reboot sh /dir/...
0
votes
1answer
58 views

DD Zero Error: No space left on device

Hi currently I am getting a problem with this script when running it on one of our xenial servers to mass wipe a batch of drives in one command. Firstly all the drives show up in lsblk, so that is not ...
1
vote
3answers
62 views

How I can add a string to each line of bash command returning multiple lines e.g. du or ls -l

I want to create a contents file for some directories, which shall be stored in several tar archives. I use du --all currentdir >> contents.list for that. I want to append the name of the tar ...
0
votes
1answer
41 views

Udev rule to connect USB to CAN Lawicell

I am using a Lawicel CAN adapter to connect to a sensor, and would like to setup a udev rule to avoid the manual can setup. The manual can setup: sudo slcand -o -c -f -s6 /dev/ttyUSB0 slcan0 sudo ...
2
votes
3answers
192 views

Table records to convert into JSON file in unix with jq

I have table on a Linux machine which has a number of records; I am running a query to get: select * from TABNAME_XYZ CID CN XY NAT UIC DATE Region 12 2123 120.9 29.0 100.0 ...
0
votes
2answers
47 views

Do multiple shell scripts sourcing a common other script interfere with each other when they modify a "sourced" variable?

If I source the same shell script from multiple other scripts, which I run in parallel, and modify a shell variable defined in the sourced script, will the sourcing scripts mess up each other's value ...
0
votes
1answer
61 views

Bash script escaping quotes

I'm writing a bash script to find all the images in the folder and find if they have corrupt endings with ImageMagick. This is the command I'm trying to automate: identify -verbose *.jpg 2>&1 | ...
-1
votes
1answer
40 views

How to use awk to cut text file

I want to use awk to cut a long text that I found from a website I want. I will save the txt from the part of the text that starts with xxx to the part that ends with xxx in a file
0
votes
1answer
81 views

Shell script gives error [closed]

I'm writing my own shell script but it when it's running, it shows: ./phone.sh: line 1: n/sh: No such file or directory ./phone.sh: line 26: `$name': not a valid identifier Can you guys check for me ...
2
votes
2answers
75 views

How to remove directories that have numbers as file names using command line?

I have a directory where there are subdirectories which have numbers as directories. For example I have a parent directory test now I have some subdirectories like 1,2,3,4,5,6,7. Now I have a local ...
0
votes
0answers
37 views

Shell cannot find a command already defined in the .bashrc [duplicate]

I'm trying to write a script that recursively calls to a command that I defined in my .bashrc using alias name-of-function ='path-to-find-it' but each time I get the error command not found. If i copy ...
0
votes
0answers
31 views

bash script doesn't run properly when I detach from screen

So I have a fairly hacky bash script that I've put together that monitors a particular Python training script (launching/interacting with some blackbox docker containers, which unfortunately have a ...
1
vote
1answer
43 views

Fusing files line by line in a directory according to their type

I have a function, save, that is been called by other functions in a for loop and the function in question is to fuse files of the same type in a particular directory (copy the contents of each of the ...
2
votes
1answer
158 views

Exit sh script if condition is met

Maybe this is a rookie question, but I am fairly new to sh scripting and I have to wait about two hours to make sure my logic is right, so I just wanted to ask here. I have a sh-script which should ...
0
votes
2answers
88 views

How do I loop through all csv files in a directory, select a range of columns and combine to single csv?

I have a large number of CSV files in a specific directory. All have at least 41 columns with matching headers, but can be as wide as 200 columns. I need to grab just the first 40 columns and append ...
2
votes
3answers
225 views

How to avoid use of rm -rf in bash scripts?

I had once a dangerous experience with the use of rm -rf, due to a unset variable. Since then, I have been extremely cautious in composing a script that involves rm -rf. Cross checking the spell ...
0
votes
0answers
69 views

How to run source and export inside a systemd unit file to start the service

I have been trying to get a service file setup for our software so that it can be started and stopped. When I manually run the commands, the server starts normal. I next took this an implemented this ...
0
votes
0answers
30 views

Contents of variable somehow lost with socat and wall

I'm not sure what is going on or which command causes the unexpected behavior, so I'll post everything I've done: I have created a script onreceive.sh containing: #!/bin/bash read INCOMING wall --...
-1
votes
1answer
45 views

How can I return only part of my grep result?

Currently I have the current command in my script: udevadm info /dev/nvme0n1 | grep P: In order to return the following information : P: /(PCIe address)/nvme0/nvme0n1/ Essentially I dont want the ...
0
votes
0answers
48 views

How to umount a script

Cron periodically has root run a script to backup certain partitions to an external USB drive. The script first removes the oldest backup, then backs up specific partitions and finally writes the ...
0
votes
1answer
38 views

xmlstarlet command for batch processing .xhtml files

I've tried xmlstarlet for processing an individual .xhtml files. xmlstarlet fo --omit-decl --recover --html file.xhtml This command process an individual files and prints output on terminal only. ...
2
votes
2answers
185 views

how to increment date from a to b?

I have 2 dates, start=20190903 & end=20210912 and want to increment till start approaches the end, increment is 13 days. have following code, but it exceeds end. #! /usr/bin/env bash start="...
-3
votes
1answer
47 views

Using output of command in further commands

I am new to Linux and I need help to write script as following. Running command to get output which is the ID#, docker exec -it scalelite-api bin/rake servers:add[https://bbb1.test.com/bigbluebutton/...
2
votes
2answers
72 views

How to iterate over list of list ( nested list ) in bash?

I have list of list such as : data = [ ['a', 'b' ], ['a1', 'b1'], ['c1', 'd1' ] ] I want to iterate over and access both elements of each nested list same time something like: for elements in ?? do ...
1
vote
0answers
51 views

Bash script for backup

I have set up a bash script to make a backup of files from my desktop computer to an external USB drive. This way, all the most recent or new files are automatically copied. This is the code: #!/bin/...