Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
2 answers
104 views

bash + how to insert date before line

lets say I want to pipe the date output in the beggining of some text for example echo "this line is test line" | date and expected output should be Wed May 22 14:55:10 UTC 2024 this line ...
King David's user avatar
0 votes
1 answer
76 views

Why do string variables in a bash script behave differently when echo'ed than they do when passed to an executable?

I have the following script: #!/bin/bash KID3=$(command -v kid3-cli) ARG1="-c 'get'" file="'1-01 - Johann Strauss - __Waldmeister___ Ouverture.flac'" echo Command: echo "$...
Frank van Wensveen's user avatar
0 votes
0 answers
201 views

how to use curl for single sign-on website or page

I've already written a shell script but it's not working. I'm getting an empty response whereas it should first return a token and also it should login then register the API. That's the task which my ...
DevOPs's user avatar
  • 1
0 votes
1 answer
34 views

shell helper function wrapping `find` and ignoring some dirs

I have a bunch of scripts which follow the pattern of: find files which match a pattern do something The problem is that there are several "hazard" directories which are large and slow, ...
Tim Hockin's user avatar
1 vote
2 answers
168 views

Why does zip --exclude only exclude files in the folder but not the folder itself?

I have the following command run in the bash shell which excludes the files in the folder scripts/. I tried the answer in Zip command for excluding directories and files but unfortunately it did not ...
Macky's user avatar
  • 93
0 votes
1 answer
151 views

How to convert code from test format to if fi format?

I have code that opens a bash file in a terminal for entering the sudo password: test "$IN_TERM" || { export IN_TERM=1 konsole -e "$0" exit 0 } && true I need ...
moninah's user avatar
  • 35
3 votes
0 answers
222 views

Is there a good way to write a shell script compatible with both bash and zsh that addresses array elements?

The fact that bash is 0-indexed and zsh is 1-indexed can cause problems. For example the following will work as intended with bash, but not zsh (PS I am aware that I don't NEED to use an array for ...
Stonecraft's user avatar
0 votes
1 answer
89 views

How deep is too deep for Nested Folders in a Bash program?

I am somewhat new to Bash and am writing a program to install .NET SDK and Runtime on each of the available Linux distros. The problem I am having is that I am trying to source functions from two ...
sonAndrew's user avatar
  • 101
0 votes
1 answer
73 views

zsh on MacOS catalina 10.15.17

I'm having a little trouble putting this all together... I want to make a simple shell script to organize and sort around 60 GB worth of music and movie files that are spread out over 3 or for 4 ...
ZJS_Spctr555's user avatar
0 votes
1 answer
62 views

Complex find statement

Have a script that I use to purge old backup directories. All the directories are named YYYY-MM-DD. The backup directories have links in them as the backups are incremental using the rsync --link-dest....
Jeremy's user avatar
  • 1
1 vote
1 answer
460 views

Maintain a fixed-size-queue of nohup jobs

Suppose I would like to run multiple nohup jobs but at each time I would like to at most run 4 nohup jobs. Is there a way to: keep track of 4 nohup job status once one of them finishes, it triggers ...
Sheng Yang's user avatar
2 votes
1 answer
140 views

Algorithm to find longest common substring

I'm having a bit of trouble coming up with a general solution to the following problem. First a bit of context. End goal: set file permissions on all files and directories created by a rpm My plan was ...
Nifle's user avatar
  • 34.5k
0 votes
0 answers
791 views

Reference shell Script within a shell Script in YAML

Is there the right way to reference a shell script written within a script in a YAML file. For eg: data: ex1.sh: | #!/bin/bash -x . /shellscriptloc/ex2.sh ... ...
Lakshmi Narayanan's user avatar
0 votes
2 answers
437 views

Bash printf: what does format specifier %P mean?

The printf statement : find directory1 -type d -printf "%P\n" | sort > file1 in the answer https://superuser.com/a/166322/856910 includes a format specifier %P. From the output of this ...
Leo's user avatar
  • 3
0 votes
1 answer
598 views

Running shell Script via Systemd.timer

So I've essentially run into the same problem as in my other question: Running shell Script via Crontab I will now run my shell script with systemd.timer but it is not working so far. Here is my ...
Sebastian Illi's user avatar
2 votes
2 answers
274 views

Why the variable doesn't change even if it should?

I have this bash script: #!/bin/bash someVar=0 tac /etc/hosts | while IFS= read line; do echo "$someVar : $line" someVar=$((someVar+1)) done echo "Finally: $someVar" ...
Elikill58's user avatar
  • 157
-1 votes
1 answer
904 views

I would Like to know what -sb and awk '{print $1}' role in this command

subdirectory_size=$(du -sb "$entry" | awk '{print $1}'). I would Like to know what -sb and awk '{print $1}' role in this command.
Mandeep Kaur's user avatar
0 votes
0 answers
96 views

How to automate mybb installation using ssh bash script

I have created this bash script to install mybb application automatically on Centos stream 8. SSH Bash script #!/bin/bash # Define variables for MyBB installation DB_NAME=mybb_db DB_USER=mybb_user ...
Mehul Kumar's user avatar
1 vote
1 answer
297 views

Can't input text in Bash function called with key binding

I have added a simple function to my .bashrc file and bound it to a key combination using the bind command. The function prompts the user for input using read, like this: myscript() { read -p &...
Scooby-Doo's user avatar
0 votes
1 answer
136 views

Script to add a tag at the end of files in a folder in case that tag is missing

I'm struggling with a shell script. I have a bunch of xml files, more than 500, and some of them has no end tag </deliveries> I created a shell script that works but only if I write the filename ...
sr_garde's user avatar
1 vote
1 answer
398 views

How to find the "pattern" in FASTA file and record the cordinates along with header

I am looking for a solution to search for a string of 17 base pairs in the FASTA file that is the human reference genome. To clarify, in simple words and put the resources, i have tried grep function ...
Santosh's user avatar
  • 13
1 vote
0 answers
54 views

$RANDOM, not so random [duplicate]

I want to print out a random number and encrypt it, like so: echo $RANDOM | sha256sum. I would expect this to take the standard output of echo $RANDOM and pipe it into the encryption function. However ...
s_dav's user avatar
  • 25
0 votes
1 answer
3k views

Systemd service exits with "success" but does not perform the .sh script at ExecStart

I'm trying to use a systemd service on a Raspberry Pi (running Raspberry Pi OS version "Bullseye", a flavor of Debian) to run a bash script on login and it seems to succeed but the script ...
A__'s user avatar
  • 327
0 votes
1 answer
37 views

if else condition not matched then move script ahed

I am creating a bash script.. Where I want to check in a file if its out is 1 or 0. If the output is one we need to execute a command if not then the script should move ahed. The part of script will ...
ph3ro's user avatar
  • 143
0 votes
1 answer
297 views

Execute a bash function inside a detached screen

I want to execute single function from the whole script into a detached screen session rather than to run the whole script inside screen. Can someone tell anyway how can I do it? Like for example #!/...
ph3ro's user avatar
  • 143
0 votes
1 answer
62 views

Getting error while setting the argument

I'm getting an error while setting the variable in argument. while [ $# -gt 0 ] ; do case $1 in '--pub') fun2exec="loadpubserveripip" ;; '--tourney') fun2exec="...
ph3ro's user avatar
  • 143
0 votes
2 answers
97 views

How to set variable by just mentioning the number on command line

I want to make a script where I can mention the matchid in argument and then it selects to value of variable like below 1=IND vs PAK 2=SA vs SL 3=AUS vs ENG So like when I run the script as ./match....
ph3ro's user avatar
  • 143
0 votes
2 answers
170 views

Call a function from command line and pass variables into that fuction

I am new to bash scripting. I want to create a script where I can execute a specific function from it with its variables. Like for example #!/bin/bash fun1(){ echo "Hello $name" } fun2(){ ...
ph3ro's user avatar
  • 143
1 vote
1 answer
2k views

Read from stdin while piping to next command?

How can you prompt a user for input, when the output is being piped? > (echo -n 'input data: '; read TEST; export TEST) | echo "done: ${TEST}" This does not show the "input data&...
Josh M.'s user avatar
  • 1,518
0 votes
1 answer
243 views

Unable to move cursor to next line after reading secret input in shell script

I am trying to read multiple inputs from user in shell script, #!/bin/bash read -sp "Enter the secret api key: " var1 read -p "Enter the mount path:" var2 If I try to run this, I ...
Ganesh Shinde's user avatar
0 votes
1 answer
2k views

How can I pack multiple bash scripts into one single executable

I have multiple bash scripts and resources required by these scripts (like music files and images) and I want to pack them all into one executable file. For example: $ find Scripts/ Scripts/ Scripts/...
Random Guy's user avatar
2 votes
1 answer
1k views

Execute EOF command remotely in one line

I am facing a problem. If I execute this command, it works normally, but I need to execute it using SSH connection. Is there a way to do it in just one line of command? Thank you for your attention. ...
Antonio Costa's user avatar
2 votes
3 answers
2k views

Delete all folders except if they have a specific file type in Linux

I looking for a command or bash script to delete all folders except if they have a specific file type (*.pdf) in the first level subfolder. folder01 a.txt y.txt folder02 b.pdf z.txt folder03 ...
Joel's user avatar
  • 123
0 votes
1 answer
184 views

shell script getopts options validations

I'm trying to check if all the validations are true and work but my logic I think is not correct and I'm new to coding. So I initialized p=0 and un=0, when user passes both option it should give error....
brucelee's user avatar
0 votes
0 answers
35 views

Bash: simplify variable replacement/upper-casing?

Is there any way to cleanly simplify this into a single line? # e.g. ARG='--some-arg' ARG=${ARG/--/} # some-arg ARG=${ARG//-/_} # some_arg ARG=${ARG^^} # SOME_ARG I'm hoping for a syntax ...
Josh M.'s user avatar
  • 1,518
2 votes
0 answers
190 views

Does tput automatically check color abilities when loading color codes?

When using tput setaf and tput sgr0, does it automatically output nothing if the session isn't tty-like or no color support is detected? So am I fine doing this? declare -r styleRed=$(tput setaf 1) ...
Jaid's user avatar
  • 21
0 votes
1 answer
429 views

put list of IP addresses into config file as text

I have config file for fail2ban where I try to put multiple IP addresses automaticly with script. But I am probably doing some mistake as the script is spamming ignoreip = ip in a loop till the fille ...
Delirium's user avatar
  • 113
1 vote
0 answers
204 views

Execute a command after matching a specific rule of iptables

Is it possible or is there any way from which a bash script can be executed using iptables? Like I wanted to execute a bash script if incoming traffic on a udp port crosses 1000pps I tried searching ...
ph3ro's user avatar
  • 143
4 votes
1 answer
3k views

How to always execute a command when a shell script function finishes?

I need to write a zsh function with multiple exit points and execute the same clean-up command at every one of them: function foo { if ... ; then ... run_cleanup return ...
Petr's user avatar
  • 3,173
0 votes
0 answers
495 views

How to log Linux commands ran from a script?

I am able to log commands executed on bash shell using export PROMPT_COMMAND='history -a > ..... , but this wont log commands executed from within a shell script. Is there any way to log command ...
Harish Reddy's user avatar
0 votes
1 answer
60 views

Refining a simple delete-item one-liner

so I was wanting to upgrade my delete-item one-liner. I want to breakup the main filepath(\HQDEVAPP004\C$\LoneStar\ProcessorHandlers\Test) into 2 variables that are defined at the top of the script. ...
Zero596's user avatar
  • 83
1 vote
1 answer
472 views

How can I get my Lubuntu system to "beep" via bash script?

Running Lubuntu 20.04LTS, and trying to get a nice beep when a bash script finishes. Before anyone votes this down, I have tried: beep and sudo modprobe snd-pcsp and say and echo -en "\007&...
confused's user avatar
  • 171
4 votes
2 answers
24k views

mv: target 'XXX' is not a directory

I am trying to write a bash script that will go through a directory and rename the files (the file name is really crazy and is not recognizable to any human as what they are) to "Chapter1.mp3&...
Jacob Hornbeck's user avatar
0 votes
1 answer
328 views

[SHELL SCRIPTING SMALL PROJECT]

I am currently trying to complete this shell script for a small project I have for my class. I'm lost as to how to go about this problem. Here is the prompt and what I have so far... What I have so ...
Lostinthesauce's user avatar
-2 votes
1 answer
1k views

List/Print oldest and newest file in each directory

Could use a bit of help guys. I need to produce a report for the oldest and newest files that are residing in each unix directory The structure is simple Main folder with multiple subfolders that ...
Tom Tom's user avatar
1 vote
1 answer
2k views

Understanding how pgrep determines process IDs

I'm currently refactoring a script that works well if executed in terminal directly but exits early due to a process check if executed from crontab. This early termination is caused by code using a ps ...
William's user avatar
  • 13
1 vote
1 answer
2k views

How to download the latest release from github and extract the zip in a folder using bash

I want to write a bash script to download the latest release from a github repo and extract the downloaded zip into a particular directory. From this gist I am able to download the zip file. The shell ...
k-c's user avatar
  • 13
1 vote
1 answer
112 views

Cancel background script run from any shell

I have a script I usually keep running in the background; it sets up port forwarding I use for database connections while developing an app whose details are irrelevant at the moment. Because I always ...
backspacer's user avatar
0 votes
0 answers
78 views

Variables inside commands inside if statement

I do not understand why this does not work: existing_user=$(ldapsearch -x -b "cn=group,ou=group2,dc=company,dc=com" -H ldap://127.0.0.1 -D "cn=admin,dc=company,dc=com" -w "...
Belphegor's user avatar
1 vote
2 answers
72 views

Creating multiple symlinks from a string

I have the following script: #!/bin/bash test="../t1,../t2,../t3" ln -sf "{${test}}" . Above this directory consists of 3 directories: ../ ├── script │   └── test.sh ├── t1 ├── ...
dogman's user avatar
  • 13

1
2 3 4 5
11