Questions tagged [bash-scripting]
Bash scripting is making scripts in the Bash shell language.
950
questions
0
votes
1
answer
54
views
<command> is a function. How to find where it is defined?
In Linux Terminal I have a command that I will call pippo
#> pippo parameters
...command executed
If I call
#> which pippo
Nothing is shown. If I try type pippo, instead, I get:
#> type ...
1
vote
0
answers
46
views
Bash Tab expansion to list all executables based on regex
How can I use regex based methods to find commands available in the ${PATH}?
For example when I press w and Tab switch. I get a list of all commands starting with w. I would like to list all ...
1
vote
1
answer
3k
views
give certificate(not the file) as input to openssl command in bash script
is there any way to give certificate(not the file) as input to openssl command in bash script ?
I placed ascii form of certicate in script as a variable . when I want to read it by openssl I got error ...
0
votes
3
answers
333
views
Swap content of two the same capacity drives
I have two the same capacity drives (equal to 1 byte). I need to swap their content (one is QVO, other one is EVO, but the selection of their application was mistaken).
Is it possible to do that by ...
2
votes
1
answer
1k
views
Pass arguments with pipe in bash
How can I pass arguments with a pipe into the next command?
Here is my command:
USER_EMAIL="[email protected]"
echo "SomePassword" | python manage.py init_admin --email=$USER_EMAIL --password= $1
...
1
vote
1
answer
1k
views
Ignore files with a specific pattern in a bash script
I am trying to ignore filenames starting with 33266158I since these files are empty and don't need any processing. I have just pasted the part where I am ignoring the file.
But this does not work and ...
0
votes
1
answer
5k
views
Setting and using a variable within a single-line Expect command in a Bash script
I have an array, $HOSTS, which contains a set of hostnames.
I have a database table that has a set of IP addresses. I want to go through each IP address in that table and send a command (hostname -s) ...
0
votes
1
answer
154
views
Why does the value of $HOME vary between Ubuntu 18.04 & 20.04 in a script using sudo
On Windows 10 v1909, I am using WSL (Ubuntu 18.04 & 20.04: 4.4.0-18362-Microsoft x86_64 GNU/Linux) and I noticed the value of $HOME within an arbitrary script varies between Ubuntu 18.04 and 20.04 ...
0
votes
1
answer
116
views
./jmap command works when script is run manually but fails when run as cronjob
I have a fairly simple script written for calculating heap size and it uses ./jmap.
The script first finds the process id and saves it in a variable PID. The same PID is given as a variable in the ...
0
votes
1
answer
281
views
notify-send Works From Shell Session, Not From Script
I am using at in coordination with notify-send/dunst as a form of reminders for myself. In an interactive bash session, doing:
$ echo 'notify-send "Test"' | at 12:45PM
works just fine and I see the ...
6
votes
1
answer
7k
views
How to get playlist name(title) with youtube-dl
I have an issue with youtube-dl in Linux, so I want to create a bash
script letting me download a playlist and put all the videos in a
separate folder having the name of that playlist
here is my ...
3
votes
1
answer
1k
views
Set individual password timeout on sudo command
I have a long running script which runs as normal user then then has sudo make install towards the end which (if I don't notice it finishes within 5 minutes) times out and fails.
In man sudoers it ...
0
votes
2
answers
49
views
Script for replacing the file name if it exists?
I'm trying to make a script that changes the name of the file if the file already exists to something like file1.txt, but I keep getting the same error: Syntax error: unexpected end of file So far I ...
1
vote
1
answer
221
views
Getting PID of MPlayer (without filtering all processes or loosing keyboard control)
I'm frequently running some kids show, while I work. To do that, I need to extend screen to tv, change audio sink etc. AND move mplayer window from primary screen to desired + make that window sticky. ...
1
vote
0
answers
128
views
is it possible to enable WPS to connect to WiFi in Windows 10 using a script?
Is there any way to connect to WiFi by enabling the WPS method, for example, from the cmd in Windows 10? I'd like to automate it in a script.
0
votes
2
answers
3k
views
I can't get echo output from the shell code
I am more new to shell programming and I am encountering such an error. Why does it give such an error?
can you please tell me?
#!/bin/bash
echo ""
echo -e " _ _ _ _ _ _"
...
1
vote
1
answer
221
views
Applying -lt on string variables in bash
I am new to bash scripting. I have to compare two values here, $i and $cdsStart: check if $i is lesser than $cdsScript, below is my code for doing the same.
inputFile="$1"
while read -r ...
4
votes
1
answer
9k
views
Add a new element to existing JSON array
How can I add "arn:aws:iam::xxxxxxx:role/3" line below "arn:aws:iam::xxxxxxx:role/2" adding a comma after "arn:aws:iam::xxxxxxx:role/2",.
Before:
{
"Version": "2012-10-17",
"Statement": [
{
...
0
votes
1
answer
106
views
Trying to list attributes in bash 4 by nested for loops
This is going to be difficult to explain but I am going to give it a shot. This snippit is working in bash 5.0.16 but not 4.2.46
I have an array basicHosts=(host1 host2 host3) this is a dynamically ...
2
votes
1
answer
5k
views
Use a variable that could contain special characters into sed?
I have a bash script that'll take any word passed to it as a parameter and then encrypt the word using an openssl command. From there I want to take the returned string and use sed to write it into ...
0
votes
1
answer
629
views
Using URLs as argument for command and for output file name
Im trying to use either XARGS or FOR in a single line to accept a list of URLS as arguments, this fails since a file name can't be a URLs. We tried doing this with FOR and XARGS, but it fails:
$for i ...
3
votes
2
answers
512
views
Test condition in if command
Any idea why echo statement is being executed in both scenarios?
Outputs it worked:
#!/bin/bash
rizwan=''
if [ -n $rizwan ]; then
echo "it worked"
fi
Replace -n with -z, and it outputs it worked ...
0
votes
1
answer
696
views
trouble with spaces in environment variable in rsync script on MacOS
I have a Bash script that I plan to run for daily backups (my HOME is /Volumes/Norman Data/me):
#!/bin/bash
# Halt the script on any errors.
set -e
# Remote server where
remote_server="example.com"
...
0
votes
1
answer
88
views
How to pass % as param in windows command line
I'm trying to login to a server where my password contains % char.
this is what I'm trying to execute via myscript.bat which has a line net.exe use x: \\SERVER_IP\C$ /user:%USERNAME% n%5Ar!33
while I ...
0
votes
1
answer
67
views
variable in bash scripting
Can someone explain why we require $ Sign in 3rd Command.
Why without dollar it is not working
[kony@HOSTNAME test]$ var1=1
[kony@HOSTNAME test]$ var1=[ var1 + 1 ]
bash: var1: command not found...
[...
30
votes
1
answer
5k
views
What is <<!END in a Bash script?
Consider:
#!/bin/bash
/u01/app/oracle/middleware/oracle_common/common/bin/wlst.sh <<!END
connect('user','pw');
p=redeploy('application');
p.printStatus();
exit();
!END
The above script is ...
0
votes
1
answer
161
views
SED failing, why?
Also see: String manipulation - get part after a certain word
My script:
# get list of curent possible F2B 'get' options, as a array (omitting the 'action..') ..
f2b_opts_cmd="$(sudo ...
10
votes
1
answer
3k
views
Get bash to respect quotes when word splitting subshell output
I have a command that outputs some parameters that I want to pass to another command. However, when I run the command in a subshell, the output is subject to word splitting unless I quote the whole ...
0
votes
1
answer
294
views
Bash: How can i send one mail instead of multiple mails
I am learning shell scripting and i was stuck at sending an email.
here in below code i am using conditions to check the files size if it is greater than 0 bytes then send an email.
if [ -s file1 ]
...
0
votes
0
answers
56
views
bash: reading array and displaying it
how can I get the array values from the variable emailFailures.
please help me on this. Thank you.
#!/bin/ksh
MY_WORK='/a585/app/data/CCN_text'
raw_data_file_count=`ls -l raw_data_*|wc -l`
echo " $...
0
votes
1
answer
62
views
Setting a variable name to output off command
I am new to writing of bash scripts. I am making a pipeline for bioinformatic data-analysis. I am running several program fx Porechop, where I want to set a variable in the output name. So I want to ...
2
votes
1
answer
156
views
How does this find state actually work in moving a file up one directory?
Can someone explain how the string manipulation in this find statement actually works? My head is about to explode trying to figure it out. :-o
From: UNIX shell scripting: how to recursively move ...
2
votes
2
answers
926
views
Unable to preserve a multi-word argument surrounded by double-quotes as a single argument in a Bash function
I've been stuck on this issue around variable expansion in Bash scripts where a multi-word argument surrounded by spaces is getting split into multiple arguments when passed down a chain of functions.
...
0
votes
1
answer
139
views
how to get a value from array in bash
In the below i am checking the exit status , if it is not zero(which is a failure) i am displaying it by echo statment
while read -r record
reccount=$((reccount + 1 ))
/usr/bin/java -jar ...
0
votes
1
answer
902
views
how to count the number of occurrences of a word in different files? -BASH
I have files like
raw_data_0, raw_data_1... raw_data_7
every file contains below data
record_count=1
emailCountFailure=0
record_count=1
emailCountFailure=0
record_count=1
emailCountFailure=0
...
0
votes
1
answer
716
views
How to run a process in background, after getting a user input in bash shell
#!/bin/bash
set -e
INPUT_NO_OF_PROCESS=$1
NO_OF_PROCESS="${INPUT_NO_OF_PROCESS:-1}"
#mkdir -p $DUMP_DIR
echo "Spawning processes=$NO_OF_PROCESS"
for i in $(seq 1 $NO_OF_PROCESS)
do
# This ...
2
votes
2
answers
2k
views
Bash- Return a value from child process to parent
I am using the below code
record_count=0
task()
{
while read -r record ; do
record_count=$(( record_count + 1 ))
.....
done < $1
}
for i in {1..5}; do
task $i &
done
how can i use the ...
0
votes
2
answers
173
views
How to compare current password with new password mac - dscl
I am writing a script to change the admin password on all of our macs.
Its a =basic script, but I would like to check if the password is already correct before attempting to change it:
if [ ...
0
votes
2
answers
833
views
How can we separate substring by using delimiter in Linux?
I have the string below:
/a585/app/data/CCN_text/CCN_split_files/ccn.email.list.file07 | /svr00c8/n585 | /a585/app/data/CCN_text | /a585/app/data/CCN_text | /a585/app/data/muttrc | 153.2.254.229 | /...
0
votes
1
answer
8k
views
Can you pass multiple parameters to a bash function by using bash -c?
I am using the bash -c command and a function:
fun ()
{
echo "$0" ## it reads the parameter $i
}
for i in {1..5}
do
bash -c "fun" $i &
done
My question is can we pass multiple parameters to ...
1
vote
1
answer
76
views
How to preview variable substitutions for a command?
u2api --zuser="$USER" --outfmtput=json SQL create_database name=$DATABASE
I would like to easily (e.g. no escaping if possible) print the resulting command instead of executing it.
Is there any ...
-1
votes
2
answers
72
views
Preserving quotation marks using bash history
You run a command like echo "hi world".
hi world
Then you run echo !! to try to display the command you just ran.
echo echo "hi world"
echo hi world
The first line outputs the command that will ...
1
vote
1
answer
1k
views
Bash command after sshpass not executed
Why are commands after sshpass not executed?
Should I somehow signal that the ssh connection has been terminated?
#!/bin/bash
SCRIPT="cd /proj
./run_server &
...
0
votes
1
answer
776
views
How to create a Bash script to execute a command until it success for max number of tries
I’m trying to executing a bash script that tries to connect to a VP with a max of 3 retrie. I'm new to bash scripting so maybe there are several error, my code is the following:
current_server=$(...
0
votes
0
answers
76
views
How to run script on remote windows machines
I have in my Network some non-domain machines which run Windows Operating System, I need to run some scripts on them remotely, but I don't know how to do that.
If you could recommend anyway to do that....
0
votes
1
answer
127
views
Stop infinite loop using GUI in bash
I created a bash script with infinite loop using this answer.I want a GUI (with one or two clicks) to stop the infinite loop whenever I want. How can I do this?
Edit to clarify more about GUI (my ...
2
votes
2
answers
121
views
Schedule a job with at command
Hello I have written a script and I want to schedule it to run at a certain time with the at command. I also want to use an argument in order to pass the time I want in the script so it can be ...
0
votes
2
answers
1k
views
How to append the contents of a .tar file to another file
I have a file named archive.tar and I want to append its contents (archive.tar is a backup file coming from a text file) to another file. I use the following command that doesn't seem to work:
tar -...
1
vote
1
answer
50
views
How to print numbered variables
I have the following variables:
display1 display2 display3 display4
and I want to print their containings in one line. I use the following command but I cannot understand why it is not working:
for(...
0
votes
1
answer
352
views
Bash copy files from multiple directories to multiple corresponding backup directories
I have multiple directories {dir1,dir2,dir3,dir4} on a Linux box.
There are multiple files in each directory (with the same extension lets say .zip) that I want to backup to corresponding directories ...