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

learn more… | top users | synonyms (2)

1
vote
3answers
70 views

Bash Script not deterministic in performing actions

I have a bash script which I invoke on system boot (Ubuntu 10.04) "Startup Applications". script: #!/bin/sh APP1='/home/ipc-display/development/projects/display-mgmt' ...
0
votes
1answer
68 views

Please explain the Awk script provided below

Can anyone please expain me step by step below AWK script written. I have the below code written in my script to format the flat file data. Just wanted to understand so that i can reuse -- I am not a ...
0
votes
2answers
190 views

Bash script returns “command not found” when outside the source folder

under my directory, /home/lucas/bin I have the following script term_multiscreen: [lucas@lucas-ThinkPad-W520]~$ sudo cat bin/term_multiscreen #!/bin/bash # Initializes ...
0
votes
4answers
124 views

What does “while test $# -gt 0” do?

I'm trying to create a function and believe I found a good working example but I don't understand all the logic behind it. More specifically, on the "while" line, could someone explain what test is ...
1
vote
1answer
189 views

Create a iptables rule if the rule does not all ready exist

Hi I've created a script to setup Nagios on my remote servers. My Script checks iptables to see if a firewall rule all ready exists and then is supposed to add the rule if it's not all ready there. ...
1
vote
4answers
86 views

How to delete a line if string is the only thing on the line

How can I use sed or something else to delete a line only if the string I'm searching for is the only thing on the line? Example output: device-address-binding: ? database-revision: 20 -- ...
0
votes
3answers
307 views

XOR of a shell variable and a binary file

I have a password stored in a shell variable (which was read from command line input). I also have a keyfile stored in a file (which was created using dd and /dev/urandom). Since I want to require ...
-4
votes
1answer
58 views

Run series of command independent of each other

If I have a file with cmd1 cmd2 cmd3 And I want to run them independent of each other, and independent whether it outputs an exit status or not (that means do not expect to end, just keep ...
0
votes
3answers
69 views

Creating list of domains using httpd.conf

I am trying to create a bash script that can generate a file which contains a full list of domains - from Apache's configuration file - that a web server hosts. It actually seems quite easy. From ...
6
votes
1answer
117 views

Determine dynamically allocated port for OpenSSH RemoteForward

Question (TL;DR) When assigning ports dynamically for remote forwarding (a.k.a. -R option), how can a script on the remote machine (for instance sourced from .bashrc) determine which ports were ...
0
votes
1answer
32 views

Expansion of *,#,% - What do they mean? [duplicate]

for j in * .* ; do cp $j ../$name-S$i.gid/${j%%. * }$i.${j#*.} done Could someone tell me what this for loop does? What do *, % and # mean? ($name is a path of a directory in which there are ...
3
votes
3answers
130 views

How to call a shell function

How can I use the integer value returned by a function in shell script that takes some arguments as input? I am using the following code: fun() { echo "hello ${1}" return 1 } a= fun 2 echo ...
1
vote
1answer
126 views

What does “if [ -e $name ]” mean? Where $name is a path to a directory

In the if [ -e $name ], what condition check is -e? $name is a variable of a path to a directory.
0
votes
1answer
52 views

Trying to pass user generated variable to an external command

I have a bash script that is asking a user for input, then passes that variable to a find command. I've tried quoting/escaping the variable every way I know, but it keeps failing. read -p "Please ...
2
votes
2answers
60 views

bash value of $LINE is not showing when defined like val=`$LINE`

I have the following bash script for some reason $LINE value is not coming on val=. I can see the line from file is read can be display by each $LINE but when defined in the val.. is not showing. ...
6
votes
2answers
254 views

Copying one file to multiple directories

I have a file that I want to copy to another 60 directories. The best way I can think of doing this is by making a bash script that has instructions to every folder like this: cp script.sh ...
3
votes
1answer
393 views

Why does the filename contains question marks when I run a script on my remote machine?

I have a tiny script that simply fetches the current date, runs a PHP script and redirect the output (and errors) to a filename containing the current date. DATE=$(date +"%Y%m%d") ...
4
votes
7answers
319 views

How can I groups numbers in a file

I have a file with numbers in float format. I can review them via sort -rn numbers.txt | less I would like though to be able to "group" them. I.e. easily see how many are in the same range. To give an ...
3
votes
1answer
266 views

Why does the history command do nothing in a script file?

If I create a file containing #!/bin/bash history and run it, I get no output. Running it manually in a terminal or sourceing the script file does produce output. Why does history not work from ...
3
votes
1answer
71 views

Write a shell script that takes in a variable from the terminal? (~$ command variable)

I am writing a shell script that takes in a time (in minutes) and opens an online egg timer set for that amount. #!/bin/bash #Opens http://e.ggtimer.com/TIMEmin where TIME = number of minutes TIME=5 ...
6
votes
3answers
163 views

What is the difference between invoking a perl script via sh or perl

I have a simple Hello World perl script. #!/usr/bin/perl print 'Hello world.'; It works fine if I run it via perl <file_name>, but it fails I run it via sh <file_name>. My ...
1
vote
2answers
145 views

How to move or copy list of files referenced in a csv file to a new folder

I'd like to write a shell script (OSX) which copies files listed in a csv file to a particular directory. I need to strip quotes from each line in the csv file. My attempt for i in $(cat myfile.csv) ...
1
vote
2answers
136 views

Output of command when piped to another command

I am running a command which does a quick checksum of some file like so find / -type f -ctime +30 -mtime +30 -atime +30 -exec md5sum {} \; | xargs -P 4 and I am trying to run it in parallel with ...
0
votes
0answers
72 views

Editing metadata with bash

I have a bunch of photos(jpeg, bmp, png) that I have arranged in such a manner that the metadata is in html form in a separate file. I would like create some script to read this html file and edit ...
0
votes
3answers
81 views

bash color echo : problem with '-n' option

here is my function to print color text: cecho() { color=${1:-""} # defaults to original color if no color specified colorreset="\E[0m" # back to black after function return while read ...
-1
votes
2answers
111 views

Start the script with sudo not working [closed]

I am trying to start the virtual machine (ORACLE VIRTUALBOX) using this script (script name: start_vm001.sh). START_VM=`/usr/bin/VBoxHeadless --startvm testvm001` EXECUTE_VM=`exec ...
1
vote
2answers
42 views

Checking files in a different folder using for loop

I have 2 folder - folder1 and folder2. Im in folder1 and need to execute a shellscript that will search for all the csv files in folder2.. The current script check *.csv in the current folder..how ...
1
vote
2answers
50 views

bash function to handle file through symlink : problem with command line arguments

I wrote a little code that will copy files given either their name or symlinks to a given directory. linkcp() { cp `echo "$(realpath $1)"` "$2" } here is the file list: $ ls -l drwxr-xr-x 2 user1 ...
4
votes
2answers
494 views

Bash command in string is executing when I create the string, not when I use it later

I'm relatively new to shell scripting, but have nearly completed a script which makes use of the lftp program. The part of the script I am having trouble with is when I create a long string of ...
1
vote
2answers
113 views

Issues Splitting CSV files

Im trying to split a csv file into multiple files using the below command..This command splits into 5 files but the data is truncated in one of the file? How do I fix this issue? >>split -n 5 ...
0
votes
1answer
38 views

Getting the line count and storing in a result set

Need to calculate the number of lines in a file and store it in a resultset. I'm sure Im wrong in this line -num_of_lines=wc -l "$file" but how can I get the executed result set? for file in *.csv ...
2
votes
2answers
67 views

Condition string matches reg.expression

So, in my script, I have to decide whether one of the parameters is a valid email address. I was trying, but it failed. if $maddr="^.$*\(@\)\(*\)\(.\)\(??*\)" then ... It's meant to mean: at least ...
1
vote
1answer
122 views

Using a Counter Loop for Environment Variable

I'm trying to write a code that moves files to a .junk directory using the built-in environment variables. My goal is that all a user would have to do is type sh junk filename1 filename2 filename3... ...
1
vote
1answer
39 views

Substring failing in shell script

for file in *.csv do split -n 5 -d -a 1 "$file" "$file" for each in $(seq -w 2 3) do echo $each filestem="$file$each" len_filestem=${#filestem} ...
0
votes
1answer
46 views

Functions defined in .zshrc not found when running script

I have a function in .zshrc that mostly updates the PATH: my_function() { PATH=... } and some scripts that depend on it, e.g. my_script.sh starts with the following lines: my_function # do ...
53
votes
1answer
2k views

Have backticks (i.e. `cmd`) in *sh shells been deprecated?

I've seen this comment many times on Unix & Linux as well as on other sites that use the phrasing "backticks have been deprecated", with respect to shells such as Bash & Zsh. Is this ...
1
vote
2answers
43 views

Splitting file using prefix

I need to split a file into 5 parts but the tricky part to append the numeric number in the prefix of the filename and not at the end. split -n 5 -d -a 2 "$file" "$file" Name of the file:- file = ...
1
vote
2answers
144 views

Remove just one word before pattern match in shell script

Input: int foo(int a, void * b, int c); Output: int foo(int, void *, int); Want to use "," as pattern to match. If "," pattern is matched then remove the previous word i.e. a, b & c.
2
votes
1answer
67 views

Can libnotify be used to execute a script?

Can libnotify be used to execute a script? I want to use a script to play a sound, or even run more complicated programs via the notify-send in bash files and other programs. Is that possible? It ...
0
votes
2answers
99 views

Bash: iterate with variable on the lines of `ls -1` output

In a simple cycle like the following for f in $(ls -1) ; do something done I would like to store each line of the output of ls -1 in the variable f. Is there a way to do this ...
4
votes
2answers
335 views

Bash's conditional operator and assignment

Can we use bash's conditional operator with assignment operators after colon? Bash reference manual explains the arithmetic operators as follows. conditional operator expr ? expr : expr assignment ...
0
votes
1answer
34 views

Special Parameter query - multiple used to obtain command name? [duplicate]

In a uni text provided us to cover bash scripting, the following variable assignment has got be stumped and I've yet to get an answer back from anyone, hence hopefully someone on here can help. ...
0
votes
2answers
72 views

Shell Script Output not written to file properly

I tried to put the output of my program into a text file. It appends the echo commands to the file properly, but the imagemagick "compare" command is not appended to the file. It just STOUD's the ...
2
votes
1answer
38 views

Splitting and renaming a file

I need to split a file with a particular format and rename it later... The Split works fine but I'm unable to refer the $file-$each inside my awk command? Any tips? for file in *.csv do split -n ...
2
votes
2answers
44 views

How to format textutil -excludedelements

I use Geektool on the Mac to display various information on my desktop. One feature of Geektoool is the ability to use shell mode to launch custom scripts or commands. I am not versed in any type of ...
0
votes
2answers
275 views

Bash script to remove user

I need to create a Bash script to remove a user. We use RHEL version 4, 5, & 6. Lets say usernames are Ray4 & Ray6 & the script name is deal. Specific tasks for this script are: Does the ...
1
vote
1answer
207 views

cd to a name-unknown directory in a known path

I am trying to automate the deployment of a webapp under development that is frequently updated. The webapp comes in the form of a zip file with unknown name, and this directory structure: ...
2
votes
3answers
746 views

Replacing the values in one file with the values in another file in bash

I am having a csv file naming List.csv in following format: Location,IP Address,Host Name,Domain,Domain Name, User Name,Manufacturer,Model,System Type, Serial Number, Operating System,RAM ...
0
votes
1answer
76 views

Job started by procmail does not appear in ps-output and cannot be stopped, even not after reboot

For testing purposes I called procmail by my .forward file |/usr/bin/procmail and by the rules in .procmailrc it started a job named "start", which was simply an infinite loop while true do ...
2
votes
0answers
38 views

What privileges do I have (find out within bourne shell script) [closed]

I am hacking away on a remote helper for git. The script is in bourne shell. I wanted to create some temporary directory in the home dir. For some reason I get permission denied. From my shell ...