A shell script is a script written for the shell, or command line interpreter, of an operating system.

learn more… | top users | synonyms (1)

14
votes
4answers
7k views

Escaping apostrophe in single quotes string in bash

I don't understand how Bash evaluates escaping of apostrophe characters in single quoted strings. $ echo ''\''Hello World'\''' 'Hello World' #works $ echo '\'Hello World\'' > # expects you to ...
3
votes
2answers
3k views

How to add commands of windows to local shell of XShell 4

XShell is a very powerful tools to ssh remote computers such as Unix/Linux. And it has built some internal commands for you to run within your Windows. Xshell:\> help Internal Commands: new: ...
0
votes
1answer
22 views

Value of variable set in 'while read' loop looses value outside the loop

The following code is a simplified version of the real life task. Of course I know that I could achieve what is done in this simplified example with a if [ ... ]. This is only to demonstrate the ...
5
votes
3answers
5k views

How to download this webpage with Wget?

I want to download the webpage http://forum.ubuntu-it.org/, but it requires a username and password. So I have used this: wget --save-cookies cookies.txt --post-data ...
0
votes
2answers
38 views

How to run a script after startup on Ubuntu 14.04?

I have scoured the web and tried numerous solutions. Nothing has worked for me so far, hence this question. I have a rails application that I run with mongrel_rails start -e production -p 80. That ...
-3
votes
0answers
9 views

working of cut -d \: -f 6 in linux [on hold]

grep loginname /etc/passwd > s this stores the complete line of loginname contains in /etc/passwd cut -d : -f 6 s this line gives the home directory. I want the working of cut -d : -f 6 s
0
votes
1answer
48 views

What do these parameters do?

What is the meaning of the switches and parameters of this command? exec su -s /bin/sh -c 'exec "$0" "$@"' root -- /opt/nsq/bin/nsqd Specifically the -- part and what exec "$0" "$@" is supposed to ...
0
votes
1answer
40 views

How do I save a string of numbers from an ongoing command to a list in a shell script?

I am trying to make a shell script for recording macros via recording the individual keycodes of each button press. The command for it looks like this: xev | grep -A2 --line-buffered '^Key*' | sed ...
3
votes
2answers
50 views

Loop in a script until file exists

I'm trying to have a script find a file in /tmp called sleep.txt but instead it keeps looping Here's what I have: #!/bin/sh set -x until [ $(ls -la | grep -w "sleep.txt" | wc -l) != 0 ]; do ...
0
votes
0answers
13 views

Grep from Log & Calculate then alert

I have a log file, which has the below lines in it. I need a bash script, which takes the values in Bold (4092.1M / 20.1G) & do the math & then alert from Zabbix [Eden: ...
11
votes
3answers
435 views

Determine type of device Bash script is being executed on (laptop or desktop)?

Is there any reliable way to determine (programmatically) from within a bash script if it is being executed on a laptop or a desktop computer? I could obviously just prompt the user to ask them, but ...
0
votes
1answer
33 views

Unix Script: Wait until a file exists

I need a script that will wait for a (examplefile.txt) to appear in the /tmp directory and once it's found to stop the program, otherwise to sleep the file until it's located So far I have: if [ ! ...
0
votes
1answer
20 views

protect the known_host file from writing - good or bad idea?

I want to protect the known_host file from writing So I want to perform the following steps on my Linux red-hat server Cp /dev/null /root/.ssh/known_hosts chattr +i /root/.ssh/known_hosts I want ...
0
votes
1answer
20 views

Exit bash script when curl gets a non 200 HTTP status

I have a bash script setup to perform a few curl requests for currency in EUR INR JPY do curl -i --data '{"currency": "'$currency'"}' -H "Accept: application/json" -H "Content-Type: ...
1
vote
1answer
48 views

file exists not working in expect script

I'm trying to check if a particular line exists in filename on a host. So only if the particular pattern is found from the grep command a dummy.txt will be created. Then I want to check if dummy.txt ...
1
vote
2answers
20 views

Not creating new file while output redirection

I'm using this for output redirection: cat filename | grep 'dis' | wc -l > test.txt But I do not want a zero byte file created if no result is found from the grep command. Is there any way this ...
32
votes
7answers
82k views

looping through `ls` results in bash shell script

Does any one have a template shell script for doing something with ls for a list of directory names and looping through each one and doing something? I'm planning to do ls -1d */ to get the list of ...
0
votes
1answer
66 views

cannot open `' for reading: No such file or directory

I am trying to run .sh file on RH6 and getting this error... cannot open '' for reading: No such file or directory The script I am running is internally referencing other scripts, located in same ...
1
vote
5answers
3k views

Get PID of process started in screen by su

i have a simple script that starts quassel-core in a screen session as different user! The script is: #!/bin/sh su ircc -c 'screen -dmS quassel /home/ircc/quassel/quassel-core' I want to start and ...
-1
votes
0answers
24 views

Come back to script main menu after command execution ends

I'm working on a simple task automation script and this is what I have done: #!/usr/bin/env bash PS3='Please enter your choice: ' options=("Prepare environment" "Create new group" "Add users to ...
0
votes
1answer
66 views

Curl globbing (asterisk expansion) on windows

On windows, in git bash (but in system console too, I think) Why curl ignores all my attempts to disable globbing and expands asterisk? $ GLOBIGNORE="*"; set -f; curl --noproxy "*" ...
0
votes
1answer
25 views

Executing Perl command from shell script not resulting into anything

I am trying to execute the below command from a shell script: perl -pi -e 's/Ç/|/g' diff_new_old.dat This command gets executed without any errors, but the execution doesn't do the intended ...
8
votes
3answers
9k views

Check if any of the parameters to a bash script match a string

I'm trying to write a script where I want to check if any of the parameters passed to a bash script match a string. The way I have it setup right now is if [ "$3" != "-disCopperBld" -a "$4" != ...
1
vote
1answer
20 views

How to make wget create appropriate zero-byte files?

I'm trying to use wget to download entire directories with their contents from a webserver. Some of the files there have zero length. Is there a way to make wget create the 0-byte file on the client? ...
2
votes
2answers
4k views

Unzip file from source to destination within user directory across multiple versions of windows

I have a source zip file which is located in a user's "My Documents" directory. It is guaranteed to always be there. I'm looking for a way to create a batch or script which will let me unzip that file ...
3
votes
1answer
29 views

How do I prepend a string to program output without waiting for the whole line?

I have a script that runs a command on a remote server using SSH. I want to prepend the string Remote: to every line of the output, but I don't want each line to be delayed until the whole line is ...
1
vote
2answers
1k views

Change many symbolic links at once?

I have about 40 symbolic links in a directory that look like this: lrwxr-xr-x 1 anna staff 45B 22 Jun 11:20 menu-bg-left.jpg -> ../../../../../hg/www/images/menu-bg-left.jpg lrwxr-xr-x ...
6
votes
3answers
723 views

Where are shell functions stored on Linux?

At first I was looking for the reason that which doesn't output anything after giving it certain programs as an argument, e.g. cd. From what I've found here, the reason probably is that cd on my ...
0
votes
0answers
15 views

Sort not respecting the key field specification?

I'm trying to sort the output of a command by a single column, but I'm having some problems with the behaviour of sort. It works fine in this scenario: $ echo 1\\n10 0 | sort -s -k1,1 1 10 0 But ...
0
votes
1answer
96 views

Make Applescript wait for an application to be closed before running a shell script

I have an applet i made using Applescript which opens an Application and then once it's loaded runs a shell script which unload's Spotlight. I need to make it then wait for me to finish using relevant ...
-1
votes
1answer
22 views

I am trying to embed a patch in a bash script - can't get patch to read the patch from a variable

read -d '' PATCH_OS <<EOF //PATCH//TEXT// EOF patch -b < ${PATCH_OS} This fails: ./script.sh: line 39: --- //PATCH//TEXT// (line 39 is "patch -b < ${PATCH_OS}"")
0
votes
0answers
29 views

xdotool ignores “ctrl” used with acroread on Linux

I'm using Acrobat Reader (v9 for Linux) as an external viewer from an editor for a generated PDF file. Since the file is often regenerated, I programmed a function key in the editor to call a shell ...
0
votes
1answer
28 views

Bash script failure

I have this script. It works fine on one of system but it's giving some error on another machine: 1 #!/bin/bash 2 EXEC_DIR=`dirname ${0}` 3 source ${EXEC_DIR}/config.sh 4 5 ...
0
votes
0answers
16 views

How to query if a wlan interface is in monitor mode?

I am trying to write a shell script to query whether a wireless interface is in monitor mode or not. I was thinking about querying a file in the linux(debian) by doing a cat /proc/.. file system to ...
1
vote
2answers
4k views

Shell Script to Start and Stop an Executable JAR in Linux Environment

I have to write a start and stop script for an executable jar (e.g., executable.jar). How to do it using shell scripting? I got success to do it for Windows environment with .bat file. But not able ...
1
vote
1answer
33 views

How can I mount NFS file in unix?

I am using Cent OS 5.6 and I have two VMs. I am trying to mount a file but unable to do so. Here's what I have done. Mkdir/uxadm Chmod 777 /uxadm vi /etc/exports /uxadm ...
0
votes
1answer
59 views

Why variables in shell are not inherited by sub-shell now that the sub-shell is implemented by fork?

When running shell command in shell scripts, a sub shell process is generated. Doesn't the process is generated by fork function? Why the variables that are not exported are not inherited? In fork, ...
12
votes
2answers
10k views

Avoid unwanted path in Zip file

I'm making a shell script to package some files. I'm zipping a directory like this: zip -r /Users/me/development/something/out.zip /Users/me/development/something/folder/ The problem is that the ...
1
vote
2answers
31 views

Need help trying to get a script to start on boot

Luke here! Although I've been using Linux as my main OS for quite a while, I'm still pretty much a noob when it comes to using it. Sorry. I have a Raspberry Pi that I'm trying to set up with the ...
0
votes
5answers
5k views

How to test if a variable is equal to a number in shell

I have this shell script that isn't working. Input: Server_Name=1 if [ $Server_Name=1 ]; then echo Server Name is 1 else echo Server Name is not 1 fi Output: Server Name is 1 But, if i ...
1
vote
1answer
331 views

How to update bash on Mac OS X Yosemite

Just trying to learn bash scripting a little. My old bash version: Bash version 3.2.53(1)-release... I've updated my bash on mac os x yosemite with homebrew: brew update brew install bash Then ...
0
votes
0answers
17 views

Staret managed server using Jenkins

I am trying to start web-logic managed server from Linux system. for that I have one shell script start_wls_managed4_btwnpmd01.sh with following code. ...
3
votes
2answers
52 views

opening several terminals at once

In my dev environment, I sometimes need several terminals to be open, each running its own script/ a server (rails, django, redis, mongo, consoles, etc) How can I create some shortcut that will open ...
1
vote
1answer
60 views

shell script file (.sh) - dynamic command

I'm trying to build a dynamic command to execute in an .sh file, however, when I do it, it seems that somehow it adds \r characters so command is not correctly executed. Notice that I'm running this ...
0
votes
0answers
57 views

Close VPN connection opened with openvpn and openconnect

I connect to a Cisco AnyConnect VPN with a script that looks like the following. #!/usr/bin/env bash cleanup() { sudo ifconfig tun1 down sudo ip link delete tun1 sudo killall openconnect ...
5
votes
2answers
8k views

Why do I Get [[: not found When Running a Script?

I'm trying to write a script that has to check if a file exists. In the console I write if [[ -a /path/to/file.txt ]]; then echo "not mod"; else echo "mod"; fi and I get not mod but when I write ...
0
votes
1answer
39 views

Launch a bash sub-shell and expect a command

From a shell script, how can I launch a bash sub-shell for the user & wait for the user to type exit at the bash sub-shell prompt? I tried bash -c expect -c 'expect "exit" {send "Exiting\n"}'; ...
1
vote
1answer
33 views

How can we configure paths for .cshrc

Within a shell script, i am trying to open a new tcsh shell and load some set of pre defined aliases and env variables which i do not want to have in default cshrc. I cannot have it in my home dir ...
16
votes
11answers
63k views

Populating Array in DOS Batch Script

How can I setup an array variable in a DOS batch script? I would like to load it with a list of file names to process. I really would like to keep this as simple as possible. Thank you.
0
votes
0answers
25 views

Don't interrupt script in sh (“try-finally” for sh scripts)

I'm trying to make a simple script to wrap a command in such a way that it runs with a swapped screen. The main target is top but I wanted it to be a general wrapper. I got it running fine with bash ...