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

learn more… | top users | synonyms (2)

2
votes
1answer
150 views

Bash - Split quoted parameters

I have a script which gets called with two parameters: ./script.sh a b I'm currently reading them through $1 and $2 (such as cd $1). My problem is that the output needs to be the same for when the ...
2
votes
2answers
47 views

Why `until` block is designed as it is just a negative version of `while`?

To my understanding, until block is just the opposite version of while, like until "condition A is met" is equivalent to while "condition A is not met". In some modern languages such like python, ...
2
votes
2answers
285 views

Bash menu with multiple parameters in one row

I have searched a couple of days and still didn't found the answer. I hope that you can point me in right direction. I would like to know how to write a bash script with a options, that can be ...
7
votes
7answers
213 views

What is the purpose of having two variables ($@,$*) to transmit the arguments of a command into a script? [duplicate]

I have read of the special variables used in a script $@ and $*. As far as I understand, the arguments used while executing the script are stored into two special variables, once all arguments into $@ ...
0
votes
1answer
51 views

Calling of scripts between init.d and home directory of server

I have a script (server_up.sh)that automatically makes server up whenever server gets rebooted and is placed on linux server in home directory. I have made another script "up_server.sh" in init.d that ...
1
vote
2answers
503 views

How to format decimal number to display the preciding zero but not the trailing ones?

I have the following script on Ubuntu 14.04.1 LTS 64-bit bash command prompt: S=0.030 F=0.150 N=10 reso=20 DIFF=`echo "scale=3; $F - $S" | bc -l` df=`echo "scale=3; $DIFF / $N" | bc -l` is=`echo ...
0
votes
1answer
104 views

capture the id of the process which called the function inside the function

I want to log the ID of the process which called a specific function in Korn shell scripting. eg Lets consider an user-defined autoload function SQUARE. Now if a TestSquare.sh script calls SQUARE ...
2
votes
2answers
198 views

menu script over ssh

I have a script that asks for input from the user. When I run this locally it does what I want however I'd really like to run it over ssh. I've tried the regular ways I'd run a script: ssh ...
2
votes
2answers
139 views

How to extract the positive numbers in the first column from an output as in the question?

I am running Ubuntu 14.04.1 LTS 64-bit with Bash 4.3.11(1)-release I have a program called harminv producing output as follows: $ h5totxt hsli0.126.h5 | harminv -vt 0.1 -w 2-3 -a 0.9 -f 200 # ...
3
votes
2answers
198 views

How to list only JPEG files from root below using the command line?

I am searching for a method to find only JPEG files/ With my limited knowledge of Linux I came to this point: list all paths that exist from root below with find / pipe the result into next command ...
6
votes
4answers
689 views

Why is it “while kill -0 $PID” and not “until kill -0 $PID”?

I may be being daft here, but if I want to do something while a process is running, why do I do: while kill -0 $PID do #... done instead of until kill -0 $PID do #... done ? kill -0 ...
3
votes
1answer
135 views

shell script is executed twice

I have this small code snippet in a shellscript to set a password: if [[ -z "${PASS+x}" ]]; then read -p "enter pass or use default [test1234]" PASS if [[ -z "$PASS" ]]; then ...
1
vote
0answers
51 views

What is the first event/file/log in linux that appears/changes on boot that signalizes network being up?

I have a vSphere farm with virtual machines and python script that handles cloning and managing of those VMs. I also have a machine (RedHat 6) that I clone if I need a new one. It has a script that ...
2
votes
3answers
250 views

What is a best practice to represent a boolean value in a shell script?

I know, that there are boolean values in bash, but I don't ever see them used anywhere. I want to write a wrapper for some often looked up information on my machine, for example, is this particular ...
1
vote
3answers
283 views

How to convert bash shell script to Markdown?

Imagine one has been working on a bunch of deploy scripts. These shells scripts are heavily documented with comments and links and are meant to be read by humans. Wouldn't it be handy to convert ...
14
votes
4answers
677 views

What is the difference between '$ . foo' and '$ ./foo'? [duplicate]

t is a simple script What is different between two case below : $ . t and $ ./t
0
votes
1answer
72 views

Where to “install” node application and best way to launch

I'm pretty new to the Linux world, I have a Node application that I would like to distribute through an apt repository, this is what I do for now: Put the node binary inside the Node application ...
4
votes
0answers
184 views

Display cron job times in a human-friendly format

Is there a way to display or is there a tool that can parse a crontab expression and display it in a human-friendly way? 10 6 * * * sh /usr/local/crons/file_check.sh For example, for the above cron ...
-1
votes
1answer
56 views

I'm trying to create a script to send message “hello” to file name Hello in home directory

And display the contents of the file in the stdout using #!/bin/bash #!/bin/bash echo"hello" >> ~/Hello cat ~/Hello should I use tee ~/Hello to display contents of file Hello in stdout ?
2
votes
1answer
368 views

ssh and run script on remote host and answer expect answer automate

The ssh from server0 to (server1,server2,server3) (no password need to SSH (trust exists between all servers and private key exists on all servers)) but a remote script on server (server1,server2 ...
2
votes
2answers
127 views

Bash command: is it possible to pass an argument before a custom command (function) or it must be only after:

I am wondering if it is possible to pass an argument to a custom command before the command? Let say I have custom command ping and I would like to pass the IP address before command: instead ping ...
1
vote
1answer
345 views

I want to create a cron job that runs a command on a remote linux box using ssh but I want ssh to answer password [duplicate]

Thank you for the reply.This is not what I am after. The ssh from server 0 to (1,2,3) (no password) but a remote script on server (1,2 & 4 ) which starts a service/application needs a password for ...
0
votes
2answers
576 views

Shell script for ssh into a Unix/Linux server from MacOS X 10.10

I am attempting to ssh into a server by using a bash script from MacOSX. #!/bin/bash spawn ssh username@gatewayserver expect "password" send "Mypassword\r" interact spawn ssh ...
0
votes
1answer
101 views

Two errors when running ssh in a bash script [duplicate]

I try to run this script against a remote machine, to carry out login check, but have some problems executing it with no errors. I have the following error when I run the script: The Error: bash: -c: ...
1
vote
1answer
687 views

LFTP mirror includes - including other directories other than what I've included

My question: How can I make sure LFTP only includes files AND directories using --include or --include-glob, and not download a bunch of extra directories from the root of the remote that aren't in ...
1
vote
2answers
497 views

How do I wait for a file in the shell script?

I'm trying to write a shell script that will wait for a file to appear in the /tmp directory called sleep.txt and once it is found the program will cease, otherwise I want the program to be in a sleep ...
-1
votes
1answer
63 views

Shell script to get all the directory starting with a certain letters

I need to write some shell script to get all the directory that start with certain letters and save the result list in a txt file eg. -all uppercase directory -all directory that starts with "Ab" ...
2
votes
2answers
155 views

remove the low version number of file

I have these files: atk-2.8.0-ia64-11.31.depot gtk+2-2.24.25-ia64-11.31.depot lzo-2.09-ia64-11.31.depot bash-4.3.030-ia64-11.31.depot gtk+3-3.6.5-ia64-11.31.depot ...
0
votes
1answer
234 views

cronjob bash script called within another shell script not working

I have a shell script which calls a bash script within it. when I run this shell script manually it works fine however when I schedule this thru cronjob, the bash script is not doing the intended job. ...
0
votes
1answer
308 views

Loop for's result in a variable for sql query

I have this part of my script for i in `cat ${RELLIST}` do for mr in `cat ${i}/DBA/install.list` do grep -i "'dba_" ${i}/DBA/sql/${mr}/*.tab 2> /dev/null | sed 's/^.*://' #grep -i ...
2
votes
1answer
159 views

Set bash script output to the line that called bash script

I've looked for the greater part of two hours trying to see if I could find a way to redirect the output of a bash script to the line that called the bash script. The best example I can use to ...
0
votes
1answer
98 views

sleep command not doing what it is supposed to do? [closed]

Im making a bash script where I have to wait for a few seconds (max 10) then run a few commands. This is because when a program is started, it also starts a few useless subprocesses which I don't ...
14
votes
4answers
3k views

What is the meaning of IFS=$'\n' in bash scripting ?

at the beginning of a shell script program in the bash is the following line: IFS=$'\n' What is the meaning behind this collection of symbols ?
4
votes
3answers
356 views

How can I find and replace only if a match forms a whole word?

My script is: n="y" while [ "{n}" = "y" ] if [ $n == "n" ]; then break; fi echo "n is $n" do read -p "Enter the word to find = " word read -p "Enter word to replace = " replace ...
2
votes
2answers
775 views

suppress stderr messages in a bash script

Consider the following (slightly silly) script name 'test1.sh': #/bin/bash # sleep 10 & echo sleep pid = $! pkill sleep When I run it, I get not only the output of the echo, but bash's ...
0
votes
2answers
3k views

Convert input string to date in shell script

My shell script: #!/bin/bash echo "$1"; startd=$(date -d "$1" +"%Y%m%d"); echo "$startd"; My command: sudo ./test.sh "20151010" The output: 20151010 20150213 it printed todays date ...
0
votes
1answer
146 views

How to show a progress bar while tar a folder recursively?

In bash-script execution of taring not shown a progress bar, how to show a progress bar while taring a directory?
1
vote
3answers
3k views

How to include python script inside a bash script

I need to include below python script inside a bash script. If the bash script end success, I need to execute the below script. #!/usr/bin/python from smtplib import SMTP import datetime ...
2
votes
3answers
245 views

Processing input line by line (with empty lines) from shell

In a shell script, I need to parse the output of a command line-by-line. The output may include empty lines, and these are relevant. I am using ash, not bash, so cannot resort to process substitution. ...
0
votes
3answers
70 views

Error when trying to accept a directory path as a command line argument

I'm trying to accept a directory path as a command line argument in order to check recently changed files - not too sure if I'm doing it correctly: script=$scriptpath find . "$scriptpath" / -user ...
2
votes
1answer
78 views

Rotate image if width is greater than a value (i.e in pixels)

I was trying to rotate few hundred images which have 7000px height in 1000+ images how to rotate them from bash.
4
votes
4answers
3k views

Bash (Ubuntu) - Strings in while loops?

I am trying to create a while loop in bash that won't continue until the user enters the word "next". I can't seem to figure out how to use strings for the condition though. #Beginning of code ...
1
vote
3answers
685 views

Read longest line in file using while read loop?

I've been googling but I can't find any scripts that uses the while loop to read the lines. I'm stuck and I'm not sure on where to start Heres the question: Write a bash script longestline.sh that ...
2
votes
3answers
1k views

Compare two .csv files

I have two files: 'file1' has employee ID numbers. 'file2' has the complete database of the employees. Here is what they look like: file1 123123 222333 file2 111222 Jones Sally 111333 Johnson ...
0
votes
1answer
147 views

While loop stuck in infinite loop

I cannot figure out why this function gets stuck. What I am trying to do is create a folder from a predetermined start date up until the present month. Unfortunately it completes all the folder ...
2
votes
3answers
297 views

What is the purpose of a start up script? [closed]

So far I know the basic meaning of a script, it is a file containing shell-commands made executable by chmod +x file and able to be run by ./ file. My friend told me, he had to copy so called start ...
3
votes
1answer
815 views

nvm command not available in bash script

I am trying to build a script in in which nvm and eventually node will get installed. I have installed nvm with cURL. I see the modifications in the .profile or .bashrc file (both work) and when ...
3
votes
2answers
83 views

What do i have to consider to write a script that reacts on a keypress?

I know i can read within a script something into a variable, like this: variable = read But i have to press enter in order to submit the value into the variable. What do i have to know in order to ...
0
votes
0answers
83 views

checkbox to automated sql scripts run

I want to provide a menu in a shell script that offers a check list of SQL scripts to run. I actually need to execute the selected SQL scripts but it's about 20 of them and that make it hard to cover ...
1
vote
1answer
197 views

bash script problem when run from desktop launcher

I have a script which does the following: Connect via sshfs to a directory on a server Within that directory, there is an encrypted volume. Open it to the device mapper. Mount to a local directory ...