The other day I saw a colleague of mine using sort to sort a number of lines he copied from a text file.
I've been trying to reproduce it myself and I cannot seem to find how.
The requirements are as follow:
Use sort from command line, plus whatever else you need to add to configure input
Paste the text to be sorted from the clipboar...
Hi,
I was playing with shell scripting, when a strange thing happened. I need someone to explain it.
I have a file 'infile', contents:
line one
line2
third line
last
a test script test.sh, contents:
read var1
echo $var1
i executed:
cat infile | ./test.sh
output was
line one
Then I did:
cat infile | read var1
echo $var1
R...
Hi,
I'm trying to get the contents of a directory using shell script.
My script is:
for entry in `ls`; do
echo $entry
done
However, my current directory contains many files with whitespaces in their names. In that case, this script fails.
What is the correct way to loop over the contents of a directory in shell scripting?
PS:...
Hi,
I'm trying to get the contents of a directory using shell script.
My script is:
for entry in `ls $search_dir`; do
echo $entry
done
where $search_dir is a relative path. However, $search_dir contains many files with whitespaces in their names. In that case, this script does not run as expected.
I know I could use for entry i...
I am trying to ftp a file from unix to as400 and executing iseries command in the script.
ftp is working fine,I am getting an error in jobd command as
HOST=KCBNSXDD.svr.us.bank.net
USER=test
PASS=1234 #This is the password for the FTP user.
ftp -env $HOST << EOF
# Call 2. Here the login credentials are suppli...
I'm trying to build a Synergy AutoStart script as per this article, the shell is giving me the error
Syntax Error
Expected end of line, etc. but found
unknown token
Here is the script I'm working on...
#!/bin/sh
. /etc/rc.common
run=(/usr/local/bin/synergyc -n $(hostname -s) -1 -f 192.168.0.108)
KeepAlive ()
{
proc=${...
My problematic code:
testMYSQL=`mysql -u $mysqlUser -p$mysqlPass -h $mysqlHost --skip-column-names --batch -D $mysqlDB -e "SELECT $select FROM $mysqlTable WHERE nameTXT='test';"`
$testMYSQL now contains:
test
test
test
Then I do:
TEST=$(echo $testMYSQL | wc -l)
echo "$TEST"
I would of thought that would work, but it doesn...
When looping recursively through folders with files containing spaces the shell script I use is of this form, copied from the internet:
while IFS= read -r -d $'\0' file; do
dosomethingwith "$file" # do something with each file
done < <(find /bar -name *foo* -print0)
I think I understand the IFS bit, but I don't un...
So I have a Linux program that runs in a while(true) loop, which waits for user input, process it and print result to stdout.
I want to write a shell script that open this program, feed it lines from a txt file, one line at a time and save the program output for each line to a file.
So I want to know if there is any command for:
-...
Are shall variables limited in size? And which is the max size a variable can hold?
...
I have the below line in the unix shell script. I want to exclude test.jar in WEB-INF/lib being added to the CLASSPATH. How can i do it?
for file in WEB-INF/lib/*jar ;
do
CLASSPATH=$CLASSPATH:$PWD/$file
done
...
I'm trying to write a script that searches a directory for files and greps for a pattern. Something similar to the below except the find expression is much more complicated (excludes particular directories and files).
#!/bin/bash
if [ -d "${!#}" ]
then
path=${!#}
else
path="."
fi
find $path -print0 | xargs -0 grep "$@"
Obviou...
I want to check if the day is Sunday, but for some reason I can't get it to work.
[[ "date '+%a'" == "Sun" ]] && echo "Today is Sunday"
...
Hello All,
There are a lot of questions on Stackoverflow about curl but I could not figure out what is that I am doing what I am not supposed to.
I am trying to call a RESTful service that I had written using Jersey API and am trying to POST an xml string to it and I get HTTP 415 error which is supposed to be a Media Type error.
Here i...
I have a script that looks like this
#!/bin/bash
function something() {
echo "hello world!!"
}
something | tee logfile
I have set the execute permission on this file and when I try running the file like this
$./script.sh
it runs perfectly fine, but when I run it on the command line like this
$sh script.sh
It throws up an ...
Is there any differences between ": > file" and "> file"?
$ : > file.out
$ ls -l file.out
-rw-rw---- 1 user user 0 Mar 18 21:08 file.out
$ > file.out
$ ls -l file.out
-rw-rw---- 1 user user 0 Mar 18 21:08 file.out
...
Hi guys,
I have a set of .php files in a folder, I want to add text just before these lines:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
What i want is to insert just before these lines...
So this is probably a long shot, but is there any way to run a C or C++ file as a script? I tried:
#!/usr/bin/gcc main.c -o main; ./main
int main(){ return 0; }
But it says:
./main.c:1:2: error: invalid preprocessing directive #!
...
I'm trying to replace a bunch of Linux shell scripts with Scala scripts.
One of the remaining challenges is how to scan an entire directory of JARs and place them into the classpath. Currently this is done in the shell script prior to invoking the scala JVM. I'd like to eliminate the shell script completely.
Is there an elegant scala i...
Are there any idioms for returning multiple values from a bash function within a script?
http://tldp.org/LDP/abs/html/assortedtips.html describes how to echo multiple values and process the results (e.g., example 35-17), but that gets tricky if some of the returned values are strings with spaces in.
A more structured way to return woul...