Questions tagged [bash-scripting]

Bash scripting is making scripts in the Bash shell language.

Filter by
Sorted by
Tagged with
0
votes
1answer
25 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
0answers
20 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 ...
0
votes
1answer
59 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
3answers
66 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 ...
1
vote
1answer
28 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@gmail.com" echo "SomePassword" | python manage.py init_admin --email=$USER_EMAIL --password= $1 ...
1
vote
1answer
29 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
0answers
15 views

Error installing glog CocoaPod “configure: error: C preprocessor ”/lib/cpp“ fails sanity check”

When running pod install I am getting an error "configure: error: C preprocessor "/lib/cpp" fails sanity check" It seems like my bash shell itself has an issue with location of clang/gcc. If I run ./...
0
votes
1answer
30 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
0answers
10 views

External keyboard startup script

I want to have a script in my Autostart that sets the keyboard layout according to if there is an external keyboard connected or not. Is there an elegant way to do this? I'm on Manjaro.
0
votes
0answers
44 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
1answer
41 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
1answer
19 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 ...
1
vote
0answers
43 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 ...
0
votes
0answers
26 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
2answers
36 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
1answer
73 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. ...
0
votes
0answers
13 views

How to start multiple PuTTY sessions from a bash script? [duplicate]

PuTTY can be started from the CLI / bash script (see the SSH.COM docu or the docu on documentation.help): putty -load "my session name" or putty @my session name Now I want to start multiple ...
1
vote
0answers
10 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
1answer
43 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
1answer
17 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
1answer
263 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
1answer
89 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 ...
0
votes
1answer
51 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 ...
1
vote
1answer
54 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
2answers
302 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
1answer
66 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
1answer
27 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
1answer
46 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... [...
28
votes
1answer
3k 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
1answer
31 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 ...
1
vote
1answer
95 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
1answer
29 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
0answers
26 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
1answer
43 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 ...
3
votes
1answer
129 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 ...
0
votes
0answers
33 views

How does a “passwd” and “adduser” command actually work on a LINUX OS?

(From a novice's point of view) The other day I was thinking about how a typical "passwd" command works in a LINUX OS. For example, when we type in "passwd", a prompt appears letting us type in our ...
1
vote
2answers
33 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
1answer
71 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
1answer
41 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
1answer
32 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 ...
0
votes
0answers
16 views

Server is unreachable when starting from xterm

I have a bash script which starts a socket.io server in a new xterm window. It also starts 2 clients both in new windows. When the clients do the handshake with the server they receive a bad request ...
0
votes
2answers
112 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
2answers
34 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
2answers
42 views

How can we seperate substring by using delimeter 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
1answer
183 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
1answer
57 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 ...
-2
votes
2answers
44 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 ...
0
votes
1answer
110 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
1answer
154 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
0answers
26 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....

1
2 3 4 5
16