> output.txt echo "==========================" >> output.txt grades < file1 >> output.txt echo "==========================" >> output.txt echo " Grades test 2 " >> output.txt" /> Unix Shell Script Question

TRENDING NEWS

POPULAR NEWS

Unix Shell Script Question

How do i comment in unix shell script?

well,

Comment lines in unix Shell script start with a hash character.
# commentmycommand my parameters
# comment

and for your information,There is no multiline comment option in shell scripting, alternatively we can use this
: <<’END’
comments’ here
and here
END

Thanks

UNIX Shell Scripts Help?

I think unless you specify what you want in clear manner I can not be of any use to you

Which one is more demanding, Python or Unix shell scripting?

It really depends on the industry in which you would like to work for. However, I would like to provide some insights from my own experience.SHELL:If you would like to work on Linux/Unix platform, then shell scripting will be the most important and fundamental thing to start with. Start with learning the basic commands [from cd, mv, ls to grep, sed, awk, etc.,] and try to automate some tasks like file manipulation, password-less login from host to target, etc., Having said that, you would come across a time sooner or later when you need Python for doing your tasks with ease.PYTHON:If you would like to work in Data Analytics domain, then python will be more demanding [R/SQL will also be equally demanding in case of data analytics] than shell scripting since you would be dealing with huge amount of data and python will be handy for it. Start with learning the basic commands as that of shell script but also explore the most commonly used modules, libraries and packages and when to use what.Hope, it helps!!Thank you for reading. For more answers, visit Karthik Panjanatham Ramaswamy

Unix shell script for matrix 2*2?

No.

Is anyone good with Unix and shell scripts?? I really need help?

This tutorial should help: http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/unixscripting/unixscripting.html

Unix script help!!! Easy script new to this need help!?

There are a couple of problems with this script, but it is nothing major. You were on the right track.

First, every shell command (such as "elif") and UNIX command has a certain syntax. I noticed that you did not leave a space after two of the elif commands. That is why you were getting the syntax error.

Next, the echo commands are telling me that you want to check if the files do NOT exist, or are NOT readable or writable. When doing the if test, the symbol for NOT is an exclamation point (!) which would have to be included before the -f -r or -w.

Finally, the last thing is that you are using the mv command which is a "move" or "rename" of the files. Because you are doing this, there will be no temp1 and temp2 file to delete with the rm command, so you will get warnings or errors about these files not existing.


On an advanced note, you are using a fixed name to do the swap (temp1 and temp2). What happens if two people try to use swap.sh at the SAME time in the same directory? They may interfere with each other and overwrite each other's files. It is good that you are doing all the extra checking if the files exist and are readable and such, but it is important to also check the success of the mv commands, and the existence of temp files.

You already know about the $1 and $# , but did you know that $$ = the current PID of your process and $? = the exit status of the command? You could use this $$ in the filename of your temporary files to make sure that they are unique. For example:

mv $1 temp1.$$
mv $2 temp2.$$
mv temp2.$$ $1
mv temp1.$$ $2

You also only really need one tempfile, since once the first file has been renamed, the second file can become the first file immediately:

mv $1 temp.$$
mv $2 $1
mv temp.$$ $2

And I don't know if this will help you or confuse you, but there are two standards to doing the if statement tests. The way you are doing it requires the use of square brackets but the other standard is as follows:

if test $# != 2
then
echo "Error: wrong amount of arguments."
elif test ! -f $1 -o ! -f $2
then
(and so on)


You may want to get yourself a copy of the O'Reilly and Associates book on shell scripting that matches the version that you are using (Korn Shell, Bourne Shell, etc..) They are a great help.

Help with a Unix Shell script! It's not working! Why?

!/bin/sh
#script name is assignment3.sh

cd ~myers/ufiles
cp file1 ~alonge/COP3353/empty
cp file2 ~alonge/COP3353/empty
cp grades ~alonge/COP3353/empty
cp t1 ~alonge/COP3353/empty
cp t2 ~alonge/COP3353/empty
cd
cd COP3353/empty

chmod u=rwx grades
touch output.txt
echo "===========================" > output.txt
echo " Grades test 1 " >> output.txt
echo "==========================" >> output.txt
grades < file1 >> output.txt

echo "==========================" >> output.txt
echo " Grades test 2 " >> output.txt
echo "==========================" >> output.txt
grades < file2 >> output.txt

chmod u=rw,g=r,o=r file1
chmod u=rw,g=r,o=r file2

echo "=========================" >> output.txt
echo " diff test 1 " >> output.txt
echo "=========================" >> output.txt
diff file1 file2 >> output.txt

echo "=========================" >> output.txt
echo " diff test 2 " >> output.txt
echo "=========================" >> output.txt
diff -w file1 file2 >> output.txt

echo "=========================" >> output.txt
echo " diff test 3 " >> output.txt
echo "=========================" >> output.txt
diff -wi file1 file2 >> output.txt

echo "=========================" >> output.txt
echo " grep test 1 " >> output.txt
echo "=========================" >> output.txt
grep -i the file1 >> output.txt

echo "=========================" >> output.txt
echo " grep test 2 " >> output.txt
echo "=========================" >> output.txt
grep ^The file1 >> output.txt

echo "=========================" >> output.txt
echo " grep test 3 " >> output.txt
echo "=========================" >> output.txt
grep 'who' file1 >>output.txt

ps | grep root >> process.txt

echo "=========================" >> output.txt
echo " Directory Listing " >> output.txt
echo "=========================" >> output.txt
ll >>output.txt

mkdir archive
tar -cf a3.tar file1,file2,grades,output.txt,process.tx...
mv a3.tar archive
gzip archive

What are some advanced unix scripts?

System startup scripts, in /etc/init.d (Linux, UNIX System V) or /etc/rc.d (FreeBSD, NetBSD, OpenBSD) are good examples of complex, configurable, and extensible shell scripts.

The files with extension .bash and .sh contain shell scripts. Bash is actually Bourne Again Shell program and sh is Bourne Shell program. Are there syntax-related differences between bash and sh scripts?

Yes, and no…The Bourne Shell is the older implementation. The Bourne Again Shell adds some extensions to the Bourne Shell but can run any Bourne Shell scripts.On quite a few systems BASH is used to provide the Bourne Shell as well, although from memory it disables some extensions when called as /bin/sh.To confuse matters on some systems /bin/sh is the Korn Shell or DASH. These all provide the same basic subset. So if you are writing scripts it is best to use only the features available in the shell you are explicitly calling.Given that the question refers to file extensions I am guessing that this is a Windows rather than a Linux or Unix question. Unix and Linux do not use extensions to determine a file type but instead use “magic numbers”. On a Linux or Unix system a shell script should always start #! followed by a path to the interpreter that should be used.I hope that this helps.

TRENDING NEWS