bash

Calling linux utilities with options from within a Bash script.

This is my first Bash script so forgive me if this question is trivial. I need to count the number of files within a specified directory $HOME/.junk. I thought this would be simple and assumed the following would work: numfiles= find $HOME/.junk -type f | wc -l echo "There are $numfiles files in the .junk directory." Typing find $HOME...

Source From Standard In (Bash on OSX)

I am trying to do something like this ruby test.rb | source /dev/stdin where test.rb just prints out cd /. There are no errors, but it doesn't do anything either. If I use this: ruby test.rb > /tmp/eraseme2352; source /tmp/eraseme2352 it works fine, but I want to avoid the intermediate file. Edit: The whole point of this is that...

How to get the cursor position in bash ?

In a bash script, I want to get the cursor column in a variable. It looks like using the ANSI escape code {ESC}[6n is the only way to get it, for example the following way: # Query the cursor position echo -en '\033[6n' # Read it to a variable read -d R CURCOL # Extract the column from the variable CURCOL="${CURCOL##*;}" # We have th...

Is there a bash command to do this?

I want to know if new files/directories have been created in a specific directory A since a fixed date time. Is there a bash command to do this? ...

change shell directory from a script?

i want to make a script (to) that makes it easier for me to enter folders. so eg. if i type "to apache" i want it to change the current directory to /etc/apache2. however, when i use the "cd" command inside the script, it seems like it changes the path WITHIN the script, so the path in the shell has not changed. how could i make this ...

bash: assign grep regex results to array

Hello everyone, I am trying to assign a regular expression result to an array inside of a bash script but I am unsure whether that's possible, or if I'm doing it entirely wrong. The below is what I want to happen, however I know my syntax is incorrect: indexes[4]=$(echo b5f1e7bfc2439c621353d1ce0629fb8b | grep -o '[a-f0-9]\{8\}') suc...

Linux: Merging multiple files, each on a new line

I am using cat *.txt to merge multiple txt files into one, but I need each file to be on a separate line. What is the best way to merge files with each file appearing on a new line? ...

How can I test if line is empty in shell script?

I have a shell script like this: cat file | while read line do # run some commands using $line done Now I need to check if the line contains any non-whitespace character ([\n\t ]), and if not, skip it. How can I do this? ...

Circular Shifts on Strings in Bash

I have a homework assignment where I need to take input from a file and continuously remove the first word in a line and append it to the end of the line until all combinations have been done. I really don't know where to begin and would be thankful for any sort of direction. The part that has me confused is that this is suppose to be pe...

How do I use a variable argument number in a bash script?

#!/bin/bash # Script to output the total size of requested filetype recursively # Error out if no file types were provided if [ $# -lt 1 ] then echo "Syntax Error, Please provide at least one type, ex: sizeofTypes {filetype1} {filetype2}" exit 0 fi #set first filetype types="-name *."$1 #loop through additional filetypes and appe...

move file from one location to another in putty

i have created folder on my server (ie finesse)- 'home' in which i have several perl(.pl) files as tt.pl, re.pl etc. now i have created new folder in 'home' folder called 'perl' and want to move tt.pl and re.pl in perl folder is there any command to do so (like cut-paste in windows)? note: i am using putty 0.60 on windows xp ...

How to search for multiple strings in a file

I want to search for the occurrence of string1 OR string2 OR string3, etc. in a file, and print only those lines (to stdout or a file, either one). How can I easily do this in bash? ...

Converting a program from c to bash script

Hello! I have created a small program in c languge.This program creates some child procceses in with the fork() function.The amount of the procceses that are created is given as the first argument of the console. I would like someone to help me convert this program from c to bash script. /* The first argument is the amount of the procce...

Redirect output from sed 's/c/d/' myFile to myFile

I am using sed in a script to do a replace and I want to have the replaced file overwrite the file. Normally I think that you would use this: % sed -i 's/cat/dog/' manipulate sed: illegal option -- i However as you can see my sed does not have that command. I tried this: % sed 's/cat/dog/' manipulate > manipulate But this just ...

How can I swap or replace multiple strings in code at the same time?

Given the following code sample: uint8_t i, in, ni; i = in = 2; ni = 1; while (2 == i > ni) in++; How can I replace i, in, and ni, respectively with either in, ni, and i or inni, inin, and nini using emacs, vi, *nix commands, or anything else? ...

Bash and regex problem : check for tokens entered into a Coke vending machine

Hi all: Here is a "challenge question" I've got from Linux system programming lecture. Any of the following strings will give you a Coke if you kick: L = { aaaa, aab, aba, baa, bb, aaaa"a", aaaa"b", aab"a", … ab"b"a, ba"b"a, ab"bbbbbb"a, ... } The letters shown in wrapped double quotes indicate coins that would have fallen through (...

Bash scripting keyboard input

I am creating a bash script for generating certificates. The openssl command that creates a certificate asks for keyboard input. This is every time the same sequence of keys: seven times [ENTER] followed by two times ['y' + ENTER]. How can I do this programmatically? ...

Getting a partial path to a file in a bash script

I have a path that is stored in a variable $FULLPATH="/this/is/the/path/to/my/file.txt" I also have another variable containing a partial path $PARTIAL="/this/is/the/" I want to remove the partial path from the full path so that I am left with: path/to/my/file.txt What's the best way to do this? ...

Move/copy files/folder in linux/solaris using only bash built-ins

There was a situation when somebody moved the whole rootdir into a subdir on a remote system, thus all the system tools like cp, mv, etc didn't work anymore. We had an active session though but couldn't find a way to copy/move the files back using only bash built-ins. Do somebody know of a way to achieve this? I even thought about copy...

Bash Shell Script: Nested Select Statements

I have A Script that has a Select statement to go to multiple sub select statements however once there I can not seem to figure out how to get it to go back to the main script. also if possible i would like it to re-list the options #!/bin/bash PS3='Option = ' MAINOPTIONS="Apache Postfix Dovecot All Quit" ...