User Tools

Site Tools


journal:spring2018:cherrma1:week10

unix week10


March 22 - 29

Alright here we go. Week 10 home stretch baby.

This weeks project looks a bit easier than last weeks which is welcome. The first thing that we are going to do if figure out how to properly cache a file using the 'tmp' directory.

I beleive in the 'pigen' script from the spf0 project there was some usage of the tmp directory.

It looks like we can use the 'mktemp' command to do this which is very convient. According to the man page for mktemp the command “create[s] a temporary file or directory”

you can run it from the command line just like this. See what happens.

 mktemp 

Mktemp also gives you the option to create a temporary directory. In this caase we just need a single file though.

Another really really nice thing that I have figured out is how to conditionally set the “-x” option for bash. If you don't know this basically gives you really nice debugging out put from the script that you are running.

I learned this little trick from an mailing list. You know who you are.

The code looks a little something like this.

 set -o xtrace 

This of course would have to be wrapped in an if statement so you could do something like this:

	if [ ${1} == "-v" ]; then 
		set -o xtrace 
	fi

I have noticed one issue with this though. The further down you put some logic like this the more debugging out put you may miss. I have also noticed that even that might not be consistent. I need to do some research to see how setting such a variable effects the output of the script.

However due to the time constraints that I am facing this week I might just have to write it off as a half baked feature.

Update: I was actaully just beinga dummy and wasn't reading my code correctly.I stuck the logic into a nice little function which as long as I put it at the top of my script I can now add some more verbosity to any of my projects!!o

Want a super easy way to create a help dialog?

egrep '^###( |$)' ${0}  

Check this out. This nice little bite will search for all the lines that beging with “###” and end with a space. I need to use this this is super helpful.

Somthing else that is pretty helpful. Is io redirction to itself. You can do soemthing like this.

 echo "This is an error" 1>&2 

This basically redirects standard output to standard error

Protip: !! is the previous command that you have typed.

Does anyone know who to make printf just be able to print a certain number of the same character? I found that it would be very useful when having to work with making tables and such. I couldn't find any functionality that I like so I decided that I would just write a function. It looks like this

	function repeatChar () {
 
		for count in `seq 0 ${2};
		do
			printf "%s" "${1}"
		done
		}

I know that it probably isn't the best way to do it, but it works and it isn't too messy.

Another issue that I was running into is using my arrays. I really like the ideas of having all of my data placed in array because it makes manipulating it a little bit easier. However my issue is that that command I was using was not behaving the way I thought it should be.

my command looks like this now:

  scoreAr=($(sed -n "${topLine},/^$/p" ${statusFile} | cut -d ":" -f1 )) 

Of course there are always going to be those very choice situations where you think, man I really wish that I could do “insert thing here”

In this case I really wanted to be able to convert all letters in my string to uppercase. Thankfully the man page of bash told me how to do exactly that!

 ${stringHere^^} #for upper case
${stringHere,,} #for lower case
journal/spring2018/cherrma1/week10.txt · Last modified: 2018/03/27 22:08 (external edit)