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

learn more… | top users | synonyms (2)

2
votes
1answer
157 views

Where are the program calls of the boot process stored

I just wrote a little program which logs all calls of bash during the boot process. This is a part of the output produced: (root) '/bin/bash-' '-c' 'gzip -d -c ...
1
vote
3answers
1k views

How do i execute a remote script with 'screens'?

I need to execute a script locally. The problem is, it needs to use screen and send the ctrl d command. How would i do this? The script will be on my local windows machine. i can use winscp, putty, ...
1
vote
2answers
2k views

Creating an empty file having a variable name in a script

I need to create an empty file using a shell script. The filename will be determined by examining all the files in a directory matching a pattern, say TEST.*, and appending _END to it so that the new ...
6
votes
3answers
3k views

How to run a script from another path, and know the script's path?

I need to run a script that access a file in the same path it is located. For example: I have the script in /home/me/folder/script.sh, and this script will access the file /home/me/folder/myfile. As ...
4
votes
2answers
5k views

How do I give all the permissions to a file for a single user that's not me?

When I want to grant access to another user to my file, I use chmod 777 file, but if I want to be sure I'm granting permission just for that user, how can I do it? -- update The file is owned by ...
5
votes
2answers
2k views

Mass .flac --> .mp3 transcoding: How to write a shell script that preserves ID3 tag information?

In recent weeks I've gone from a fairly 'hands-on' approach to .flac --> .mp3 transcoding, to one that's far more 'set & forget'. The first step was to stop using a GUI front end (Audacity with a ...
6
votes
2answers
7k views

Why is my variable being localized in one 'while read' loop, but not in another seemingly similar loop [duplicate]

Why do I get different values for $x from the snippets below? #!/bin/bash x=1 echo fred>junk ; while read var ; do x=55 ; done <junk echo x=$x # x=55 .. I'd expect this result x=1 cat ...
3
votes
5answers
3k views

Script to list only files of type ASCII text in the current directory?

How to write a shell script which searches the current UNIX directory and returns the names of all files of type ASCII text?
17
votes
4answers
6k views

How can I detect if the shell is controlled from SSH?

I want to detect from a shell script (more specifically .zshrc) if it is controlled through SSH. I tried the HOST variable but it's always the name of the computer which is running the shell. Can I ...
3
votes
2answers
8k views

How to get the char at a given position of a string in shell script?

How to get the char at a given position of a string in shell script?
4
votes
2answers
1k views

How can I pause in a shell script?

How can I make my shell script pause before continuing?
2
votes
4answers
4k views

Establish openvpn tunnel in bash script

I'm trying to write a script which will establish an openvpn tunnel when the computer boots up. The main problem lies in inputting the pkcs12 password. I realise it's very bad practice to have a ...
5
votes
6answers
3k views

Compare files that are in directory 1 but not directory 2?

I'm having trouble with a bash script I want to make I know ls will list files that are in a directory but I want it to list directories that are in directory1 but NOT in directory2, and then list ...
3
votes
2answers
4k views

How to catch optioned and non optioned arguments correctly?

I want to write a shell script which will take some arguments with some options and print that arguments. Suppose the name of that script is abc.ksh. Usage of that script is - ./abc.ksh -[a ...
4
votes
4answers
809 views

How to get the network status (online/offline) and attribute it to a variable in shell script?

How to get the network status (online/offline) and attribute it to a variable in shell script?
16
votes
6answers
11k views

How to get my own IP address and save it to a variable in a shell script?

How can I get my own IP address and save it to a variable in a shell script?
3
votes
3answers
3k views

Reading an Microsoft Excel File

How to read an XLS File (Microsoft Excel) using unix Bash / Corn shell script?
6
votes
2answers
6k views

Can I make scripts use aliases instead of commands?

I have an alias for a command (I'm setting up a Python development environment) alias python=~/virtualenv/bin/python so that I can run ~/virtualenv/bin/python by just typing python. Now in my ...
7
votes
1answer
1k views

Converting html table into ncurses-like ascii table?

I have some documentation in an html table. I want to convert the table to an ascii table, like you see when you get a mysql command line result back, like this: +------------+------------+ | header ...
4
votes
3answers
6k views

Simple Shell Script with Arithmetic issue… ** is giving me trouble

When I run this script I get this error: ./myscript.sh: 16: arithmetic expression: expecting primary: "1 ** 1" When I run this shell script with bash, as in #! /bin/bash on the first line, the ...
15
votes
3answers
13k views

Find the owner of a directory or file, but only return that and nothing else

I am looking for a command that will return the owner of a directory and only that--such as a regex parsing the ls -lat command or something similar? I want to use the result in another script.
13
votes
4answers
7k views

What is the meaning of $? in a shell script?

When going through one shell script, I saw the term "$?". What is the significance of this term?
8
votes
2answers
674 views

date - years prior to 1901 are treated as invalid

I have date (GNU coreutils) 7.1 installed on my system. If I try to check dates prior to 14-Dec-1901, I get an "invalid date" error. For example, $ date -d 1901-12-13 date: invalid date ...
2
votes
2answers
1k views

How to build a long command string?

I've a sequence of commands to be used along with lot of pipings, something like this: awk '{ if ($8 ~ "isad") {print $2, $5, "SE"} else {print $2, $5, "ANT"} }' ...
0
votes
2answers
1k views

How to run a shell script containing an awk command

How to run this script (called count.sh)? awk 'BEGIN{ x=0 ; while (x < 5) { x+=1 ; print x ; } }' I'm trying to run it with sh count.sh but it's giving me an error.
4
votes
1answer
1k views

Bash script IDE

Is there a bash/ksh/any shell script IDE. Don't you get annoyed when you forget the space inside if or I don't know, some minor syntax mistakes you do from time to time, but takes you a long time to ...
2
votes
1answer
1k views

Attempting to update Amazon Route53 using a script, but domain is not being updated

I have several Amazon EC2 instances, running Ubuntu 10.04, with which I'd like to use Amazon's Route53. I setup a script as described in Shlomo Swidler's article, but I'm still missing something. ...
4
votes
2answers
5k views

How to get elapsed time from two “text based” dates

I would like to know if there is a way to calculate the difference between two times in bash. I have two fields that are extracted from a log file: Start time: Feb 12 10:02:10 End time: Feb 12 ...
7
votes
4answers
10k views

Copy/rename multiple files using regular expression (shell script)

I have a collection of files matching a pattern such as 'assignment02.cc', 'assignment02.h', 'assignment02.txt', etc. I would like to copy/rename these files into 'assignment03.cc', 'assignment03.h', ...
3
votes
4answers
574 views

shell scripts that respond to console output

Disclaimer:: I am not an active shell scripter How does one create a script that responds to console output? For instance, I'm trying to setup a cron that periodically svnsync 's changes to my ...
1
vote
2answers
761 views

How to move files with specific extensions to newly created directories

I want to mv files with specific extensions to newly created directories. This script moves files with all the extentions in all the newly created folders, which is not the intent. Instead, it should ...
5
votes
4answers
9k views

Processing bash variable with sed

Been banging my head off a wall on this bash variable LATLNG contains a latitude & longitude value in brackets like so (53.3096,-6.28396) I want to parse these into a variable called LAT and ...
8
votes
5answers
2k views

How to run part of a script with reduced privileges?

I have the following problem: On every machine running Postgresql there is a special user postgres. This user has administrative access to the database server. Now I want to write a Bash script that ...
3
votes
1answer
632 views

Storing `find` parameters in a variable

I'm running the following bash command: find . \( -iname '*.aif' -o -iname '*.pdf' -o -iname '*.exe' -o -iname '*.mov' \ -o -iname '*.doc' \) -exec rm -f {} \; I'm running the same parameters ...
3
votes
2answers
1k views

automatically load shell scripts from /usr/bin

Is there a way to have bash automatically load shell scripts I create and place into /usr/bin? Or is there a different place I should put custom shell scripts so that they are automatically loaded? ...
3
votes
1answer
7k views

Filtering on dates with grep and awk

I have created the alias below in my .bash_aliases file alias auth="grep \"$(date|awk '{print $2,$3}')\" /var/log/auth.log | grep -E '(BREAK-IN|Invalid user|Failed|refused|su|Illegal)'" ...
3
votes
2answers
2k views

Add a one-off scheduled task through a shell script?

I'd like to execute a task at a given time, once. I know I can just use crontab -e to add it there, but I'd like to do that through a shellscript. crontab -e gives me some temporary file to edit ...
2
votes
4answers
2k views

Shell script error message

I am trying to learn shell scripting by reading linuxcommand.org. For some reason I keep getting the error "Not Found", even though it runs all the commands. The error codes I get are: ...
8
votes
3answers
26k views

How can I concatenate a shell variable to other other parameters in my command lines?

How can I concatenate a shell variable to other other parameters in my command lines ? For example, #!/bin/sh WEBSITE="danydiop" /usr/bin/mysqldump --opt -u root --ppassword $WEBSITE > ...
4
votes
3answers
250 views

Best way to work through / display a tree of images sorted by size

I've got a deep directory tree containing .PNG files. I'd like to find all the .PNG files in the directory, sort them in order of size from smallest to largest, and then display every 50th image. ...
10
votes
1answer
2k views

How do I make a shell script that sends output to a process

I'm currently running a server console program in a screen because I need to both read it and occasionally send commands. I'd like to run the app as a deamon in the background (start/stop it with ...
14
votes
2answers
3k views

How do I test to see if an application exists in $PATH?

I'm trying to write all of my sh startup/env scripts to work with as much DRY and as much: "works on every *nix I clone it to", as possible. This means making sure that if I try to run code that's not ...
2
votes
1answer
180 views

Why does the local::lib shell code use eval and $()

using local::lib requires you to add a line to your ~/.shellrc eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib) I don't understand what the point of using eval, and encasing the statement in $() ...
14
votes
4answers
820 views

keep duplicates out of $PATH on source

I have the following code that's source-d by my .shellrc PATH="${PATH}:${HOME}/perl5/bin" PATH="${PATH}:${HOME}/.bin" export PATH but if I make changes to other code and then source this file, my ...
37
votes
2answers
3k views

$VAR vs ${VAR} and to quote or not to quote

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
8
votes
4answers
8k views

Bash script testing if a command has run correctly

I am working on a bash script that I would like to work for several types of VCS. I am thinking of testing if a directory is a repo for a system by running a typical info command and checking the ...
5
votes
3answers
7k views

Storing output of command in shell variable

I have an operation using cut that I would like to assign result to a variable var4=echo ztemp.xml |cut -f1 -d '.' I get the error: ztemp.xml is not a command The value of var4 never gets ...
4
votes
1answer
3k views

Recursively compare directory contents by name, ignoring file extensions

I have a directory containing about 7,000 music files. I used lame to recursively re-encode all files in it to a separate directory, outputting all files with the same relative path and file name. ...
6
votes
1answer
1k views

Reason for ksh obsoleting -eq

The latest version of ksh obsoletes using -eq within [[ ]] blocks, prefering (( )) instead. Why is this? I can't find any documentation on the advantages of (( )) over [[ ]] anywhere, and I find that ...
1
vote
0answers
830 views

Which scripting language is most widespread in system administration tasks? [closed]

I am migrating to Linux and have some experience with the Mac OS X command line/bash. I'd like to automate system admin tasks via scripting, but I am unsure as which language is the most used in the ...