Simple BASH script to update subversion files
This is just a simple BASH script that will update all .svn files in a specified directory. If an update fails, it will attempt to update all the subdirectories in the failed one, so as much will be updated as possible. Theoretically, you should be able to supply this script with only your root directory ( / ), and all the .svn files on your computer will be updated.
#! /bin/bash
# Contributor: Dylon Edwards <[email protected]>
# ================================
# svnup: Updates subversion files.
# ================================
# If the user supplies no arguments
#+ then, update the current directory
#+ else, update each of those specified
[[ $# == 0 ]] \
&& dirs=($PWD) \
|| dirs=($@)
# Update the target directories
for target in ${dirs[@]}; do
# If the target file contains a .svn file
if [[ -d $target/.svn ]]; then
# Update the target
svn up $target || {
# If the update fails, update each of its subdirectories
for subdir in $( ls $target ); do
[[ -d $target/$subdir ]] &&
( svnup $target/$subdir )
done
# If the target file doesn't contain a .svn file
else
# Update each of its subdirectories
for subdir in $( ls $target ); do
[[ -d $target/$subdir ]] &&
( svnup $target/$subdir )
done;
fi
done
Cerebral wrote:
To filter out blank lines, you could just modify the awk command:
${exec awk '!/^$/ { print "-", $_ }' stuffigottado.txt}
very nice; awk and grep: two commands that never cease to amaze me.
Similar Messages
-
Solaris 11 - run a simple BASH script on computer startup
I need to have a simple BASH script run on my Solaris 11 machine automatically whenever the computer (re)starts. It should be run with root permissions and after the computer has fully booted. What is the easiest way to do that?
Thank you
DusanHi user9368043
Yes, that should be right, and be intended this way.
See /etc/rc3.d/README and the following part from smf(5):
Legacy Startup Scripts
Startup programs in the /etc/rc?.d directories are executed
as part of the corresponding run-level milestone:
/etc/rcS.d milestone/single-user:default
/etc/rc2.d milestone/multi-user:default
/etc/rc3.d milestone/multi-user-server:default
Your question concerning upgrading to Solaris 11.1:
In the Gnome menus, you should look for (and start)
System --> Administration --> Update Manager
Let it do its work. It will give you a new boot environment, containing Solaris 11.1. Possibly, you have to perform upgrading twice. With "beadm activate", see beadm(1M), you can go back to Solaris 11.0 whenever you want.
"Local" parts of your zfs root pool, like /usr/local, home directories, /root, and so on, should be in separated file systems, and be mounted outside the root pool before upgrading. They are availlable then from any boot environment, and will not be duplicated. See more in zfs(1M), zpool(1M).
I strongly recommend upgrading. Solaris 11.1 is great. -
Simple bash scripting help needed..
I want to learn som simple bash scripting in order to automate various tasks.. Im totally noob, so bear with me
First of all I would like to set configs without using nano.. is there a simple command for this? For example if i want change my hostname in /etc/rc.conf.. how can i print the current vallue and how can i change it`?
i was thinking something like this to get the current value:
# cat /etc/rc.conf | grep HOSTNAME=
which returns HOSTNAME="myhostname"
how can i change this value with one or more commands whitout touching the rest of the file?abesto wrote:
A slightly naive solution:
CHOICE="lisa"
NAMES="homer marge lisa bart maggie"
if [ "`echo \" $NAMES \" | grep \" $CHOICE \"`" ]; then
echo "this is how you do it"
fi
The extra spaces inside the escaped quotes are to ensure that only a whole word is "matched".
You can also replace the elif's with a loop through a list of "the other variables". Then you'd use the loop variable instead of $CHOICE above.
grep can check on word-bounderies with \< and \>, or with the -w switch. The -q switch suppresses any messages and exits with exit-code 0 when the first match is found:
if echo "${NAMES}" | grep -qw "${CHOICE}"; then
Nice and readable, should work, but i haven't tested it
EDIT:
Procyon wrote:CHOICE="lisa"
NAMES="homer marge lisa bart maggie"
if [[ $NAMES =~ $CHOICE ]]; then echo match; fi
This one also matches elisa, ie. no check on word bounderies. You should be carefull with that
Last edited by klixon (2009-04-23 09:40:22) -
Repcheck - A Simple Bash Script To Monitor Remote Repos Commits
Hello all,
I'm using a few git/svn packages from the AUR, and only recently realized that while to PKGBUILD itself is able to pull and build the latest version, the package version in the AUR will not update, unless a new PKGBUILD is pushed by the maintainer, and so my update monitor isn't aware of those remote updates.
I've looked for a convenient way to track such changes, but all I could find were "live" monitors that run constantly and check for updates in a given repo in a set interval.
It didn't fit my needs, so I wrote a script myself.
The script basically maintains a file containing repo address and current revision number (for SVN) or hash (for GIT).
Whenever an update operation is done, all remote hashes are compared to those stored in the file and if updates are found, a notification is sent.
In case of GIT repos, the script also tries to find corresponding AUR package (I couldn't find a standard for SVN addresses...).
It is up to the user to update currently installed version to latest remote version if he wants, script only displays notification.
Dependencies:
- bash
- git
- subversion
- libnotify
* EDIT *
Updated script in next post.
Last edited by adam777 (2013-06-14 11:55:29)#!/bin/bash
RepVersionsFile=~/repversions
TempRepVersionsFile=~/repversionsupd
TempRepUpdatesFile=~/repupdates
function add_to_list()
if [ -f $RepVersionsFile ]
then
tmp=$(cat $RepVersionsFile | grep $1)
if [ -n "$tmp" ]
then
exit
fi
fi
tmp=$(echo $2 | grep ".git")
if [ -z "$tmp" ]
then
current_hash=$(svn info $2 | grep Revision | awk '{ print $NF }')
else
current_hash=$(git ls-remote $2 | grep HEAD | awk '{ print $(NF-1) }')
fi
echo -e "$1 $2 $current_hash" >> $RepVersionsFile
function remove_from_list()
if [ ! -f $RepVersionsFile ]
then
exit
fi
tmp=$(cat $RepVersionsFile | grep -v $1)
if [ -z "$tmp" ]
then
rm $RepVersionsFile
exit
fi
echo -e "$tmp" > $RepVersionsFile
function check_all()
while read pkgname address hash
do
tmp=$(echo $address | grep ".git")
if [ -z "$tmp" ]
then
remote_hash=$(svn info $address | grep Revision | awk '{ print $NF }')
else
remote_hash=$(git ls-remote $address | grep HEAD | awk '{ print $(NF-1) }')
fi
if [ $remote_hash != $hash ]
then
echo -e "$pkgname" >> $TempRepUpdatesFile
fi
echo -e "$pkgname $address $remote_hash" >> $TempRepVersionsFile
done < $RepVersionsFile
if [ -f $TempRepUpdatesFile ]
then
notify-send "Updates Found On Remote Repos" "`cat $TempRepUpdatesFile`"
rm $TempRepUpdatesFile
fi
rm $RepVersionsFile
mv $TempRepVersionsFile $RepVersionsFile
case $1 in
add-address)
add_to_list $2 $3
remove-address)
remove_from_list $2
update)
check_all
echo "Enter Your Choice:";
echo "1 For Adding A Repository";
echo "2 For Removing A Repository";
read userchoice
if [ "$userchoice" == "1" ]
then
echo "Please Enter Package Name";
read pkgname
echo "Please Enter Repository Address";
read repaddress
repcheck add-address $pkgname $repaddress
fi
if [ "$userchoice" == "2" ]
then
echo "Please Enter Package Name";
read pkgname
repcheck remove-address $pkgname
fi
esac
Last edited by adam777 (2013-08-07 16:09:00) -
Using Bash script to edit config file
This is a really simple question, but given that I'm just learning Bash scripting and having this solved now would be really illustrative for me, I would really thank some help here.
I'm using uzbl, and running Tor+Polipo. So, as you will see below in the tail of the config file, there is a line to redirect the requests of uzbl through Polipo.
# === Post-load misc commands ================================================
sync_spawn_exec @scripts_dir/load_cookies.sh
sync_spawn_exec @scripts_dir/load_cookies.sh @data_home/uzbl/session-cookies.txt
# Set the "home" page.
#set uri = https://duckduckgo.com
# Local polipo proxy
set proxy_url = http://127.0.0.1:8123
# vim: set fdm=syntax:
What I want to accomplish is to comment in/out that line with a key shortcut on Awesome. I've thought of doing 2 scripts to do so and using 2 differente key shortcuts, but I want to "toggle" the proxy redirection with only 1 shortcut. To do so, I suppose that the script should go something like:
if
tool 'set proxy_url = http://127.0.0.1:8123' config_file
then
tool '#set proxy_url = http://127.0.0.1:8123' config_file
else
if
tool '#set proxy_url = http://127.0.0.1:8123' config_file
then
tool 'set proxy_url = http://127.0.0.1:8123' config_file
fi
fi
I know little about sed, but I think is the tool for this job. The most intriging part to me is to ask sed to print the regular expression when it finds it in the config file, and use that as an input in the conditional statement.
Well, this is a mess I have done here. Hope there is a simple answer to this.
Thanks in advance.-You can do this with a single sed command:
sed -i 's/^#set proxy_url/set proxy_url/;
t end;
s/^set proxy_url/#set proxy_url/;
: end' config_file
This edits the file in-place (-i) and first tries to replace the commented with the uncommented line. If that suceeds, sed jumps to the "end" label. If not, it tries to replace the uncommented with the commented line. Thus you don't have to include any logic about the current state: if the first substitution succeeds, the line was obviously commented, if not, it was uncommented, and the second substitution should succeed.
Note that my knowledge of sed is very limited. There might be a simpler way to do this.
EDIT: For the sake of example, here's how to do the same in bash using regular expressions. Note how this script needs to use a temporary file to simulate in-place editing, how it needs to process the file line by line manually, etc. All things that sed does out of the box...
#!/bin/bash
tmp=test.conf.tmp
echo -n "" > "$tmp"
while read line; do
if [[ "$line" =~ ^#set\ proxy ]]; then
echo "${line/\#/}" >> "$tmp"
elif [[ "$line" =~ ^set\ proxy ]]; then
echo "#$line" >> "$tmp"
else
echo "$line" >> "$tmp"
fi
done < test.conf
mv test.conf.tmp test.conf
To answer your original question, the line
if [[ "$line" =~ ^#set\ proxy ]]; then
reads: if the line begins with a "#", followed by "set proxy", then...
Last edited by hbekel (2011-03-20 10:40:16) -
Bash script to dumpstream many files simultaneously with mplayer
hi guys
i have a problem which i´m sure can be solved with the power of bash scripting
unfortunately i´m no bash scripting guru and all my experiments failed so far
the problem:
i have a file in which are links(streaminglinks)
mplayer offers the funtion to dump such a stream with simply issuing
mplayer -dumpstream mms://path/to/video -dumpfile video1
for example.
now i want mplayer to download this streams specified in the links-file automatically.
basically all it required is a bash script which goes through the link file and generates a command like mplay -dumpstream <link> -dumpfile video<n>
(where n is the nth link) and execute it.maybe there a even simpler solutions
well since i´m not that experienced with bashscripting i can´t solve that problem at my self....
i´m grateful for any helphey guys
thx for the two scripts.
my approach was nearly the same as your´s kraluz with the difference that it doesn´t work
but they both have a little blemish
they download the files sequentially not simultaneously
how could that be realised
thx in advance -
Simple bash script to add a '-' [Solved]
I need to write a small bash script to add a '-' to each line in a file before displaying via conky!
Todo
- Get Milk
- Buy Food
- Pay Bills
Currently I use
TEXT
Todo
${hr}
${head /home/mrgreen/.stuffigottado.txt 30 20}
In .conkyrc but have to add '-' each time I edit .stuffigottado.txt
Thanks in advance....Cerebral wrote:
To filter out blank lines, you could just modify the awk command:
${exec awk '!/^$/ { print "-", $_ }' stuffigottado.txt}
very nice; awk and grep: two commands that never cease to amaze me. -
Tidy -- simple python script to clean annoying files and directories
Hi all,
recently I opened a much-used flash drive and there was a lot of files like Thumbs.db, Mac OS' ._*, .DS_Store, etc all over it, making using it really annoying.
So I decided to mimic a simple utility I saw as a plugin in Rockbox, which takes all of these files and deletes them.
The result is a simple python script which you can find at:
http://github.com/houbysoft/short/blob/master/tidy
Usage should be self-explanatory. Be warned, by default, it deletes everything that matches the regular expressions without warning (this should be fine though, so if you want to be safe, try the -s and -v (simulate, verbose) or -p (prompt) options first.
As usual, any feedback is welcome, and if you know of other files it should clean, please post them here!Hi all,
recently I opened a much-used flash drive and there was a lot of files like Thumbs.db, Mac OS' ._*, .DS_Store, etc all over it, making using it really annoying.
So I decided to mimic a simple utility I saw as a plugin in Rockbox, which takes all of these files and deletes them.
The result is a simple python script which you can find at:
http://github.com/houbysoft/short/blob/master/tidy
Usage should be self-explanatory. Be warned, by default, it deletes everything that matches the regular expressions without warning (this should be fine though, so if you want to be safe, try the -s and -v (simulate, verbose) or -p (prompt) options first.
As usual, any feedback is welcome, and if you know of other files it should clean, please post them here! -
Simple bash script in SL to remove files
1. SL on MBP
2. launch Terminal
3. pico remove-files
4. in my script are two simple rm /path to file type statements
5. save file in user/bin directory
6. type name of command
7. get "command not found" error
no wonder 99.9999% of the world doesnt program - why doesnt this simple setup work right ?Chris Chamberlain1 wrote:
just guessing, if it type ./remove-files this script works.
That's the traditional way to invoke a program or command file if its location is not in your path. If that file is in /usr/bin and /usr/bin is in your path, I'm not sure why your situation doesn't work. On my Mac the directory bin in /usr is owned by root:wheel. If yours is the same, how did you manage to create your script there without permission manipulations? What exactly did you mean when you first mentioned "save file in user/bin directory"? Did you really mean /usr/bin or something else? If you meant some other location, you might want to add that location to your path with this command:
PATH=yourotherdirectory:$PATH -
Another simple bash script to clean pacman cache
here is a simple script that I have written which cleans pacman cache folder in a way that only the packages which are now "updated" in the repositories, will get removed. This is different from what "pacman -Sc" does. pacman -Sc also removes any package which is not installed, while this script keeps all the packages which are updated whether they are installed or not.
The functionality is some how like what "apt-get autoclean" does in debian.
to use this script you need to run it with "list" or "clean" arguments. you can also use the "help" argument for more help.
I hope it helps
#! /bin/bash
# clcache - This script cleans pacman cache folder in a way that only the packages
#+ which are now updated in the repositories, will get removed. This is
#+ different from what "pacman -Sc" does. pacman -Sc also removes any package
#+ which is not installed, while this script keeps all the packages which are
#+ updated whether they are installed or not.
# I have tweaked this script to be as fast as possible, it might still need a
#+ couple of minutes to compelete based on the size of your cache folder.
# to use this script you need to run it with "list" or "clean" arguments.
# you can also use the "help" argument for more help.
# This script is written by "Ali Mousavi". Please report bugs to [email protected]
DIR="/var/cache/pacman/pkg" #the default directory of pacman cache.
ROOT_UID=0 #Only users with $UID 0 have root privilages.
TMPFILE="/tmp/cache.tmp"
# Run as root
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script"
exit 1
fi
# Check for the arguments
if [ -z "$1" ]
then
echo -e 'What should I do?\nValid Argument are "list", "clean" or "help"'
exit 1
elif [ "$1" = "list" ]
then
ACTION="ls"
MESSAGE="Are you sure you want to continue?"
elif [ "$1" = "clean" ]
then
ACTION="rm -vf"
MESSAGE="Are you sure you want to remove outdated packages? This process can not be undone!"
elif [ "$1" = "help" -o "$1" = "-h" -o "$1" = "--help" ]
then
echo -e "This script checks the packages in your pacman cache directory and removes the packages that are outdated. It doesn't matter if the package is installed or not.\n\n3 arguments can be passed to the script:\n\nlist:\n\tchecks for package that are outdated and prints the names.\n\nclean:\n\tremoves outdated packages.\n\nhelp,-h,--help:\n\tprints this help text.\n\nThis script is written by \"Ali Mousavi\". Please report bugs to [email protected]"
exit 0
else
echo 'Valid Argument are "list", "clean" or "help"'
exit 1
fi
# Check if the user is sure!
echo "This might take a while based on the amount of cached packages."
echo -n "$MESSAGE(y/n) "
read ANS
if [ $ANS = "y" -o $ANS = "Y" -o $ANS = "yes" ]
then
echo "Processing packages..."
elif [ $ANS = "n" -o $ANS = "N" -o $ANS = "No" ]
then
echo "Exiting on user request"
exit 0
else
echo "Invalid answer"
exit 1
fi
# Process the packages
cd $DIR #change to cache directory.
pacman -Sl | awk '{ print $2" "$3; }' > $TMPFILE
for f in $(ls $DIR)
do
pname=$(file $f | cut -d: -f1) #Produces filename, like: fetchmail-6.3.19-1-i686.pkg.tar.xz"
spname=$(echo $pname | sed 's/-[0-9][0-9]*.*//g') #removes package version: fetchmail
pver=$(echo $pname | sed 's/.*-\([0-9\-\.][0-9\-\.]*-[0-9\-\.][0-9\-\.]*\).*/\1/g') #using pacman -Qi for all files takes a lot of time.
if [ $(echo $pver | grep '[^0-9\-\.\-\-]' | wc -l) != 0 ] #checks if package version is alright
then
pver=$(pacman -Qpi $f | grep Version | awk '{print $3}')
fi
newpver=$(grep -e "^$spname " $TMPFILE | awk '{ print $2 }')
if [[ $newpver != $pver ]]
then
$ACTION $f
fi
done
rm -f $TMPFILE
echo "Outdated packages processed successfully!"
exit 0
Last edited by tuxitop (2011-09-13 09:24:26)tuxitop wrote:# Check for the arguments
if [ -z "$1" ]
then
echo -e 'What should I do?\nValid Argument are "list", "clean" or "help"'
exit 1
elif [ "$1" = "list" ]
then
ACTION="ls"
MESSAGE="Are you sure you want to continue?"
elif [ "$1" = "clean" ]
then
ACTION="rm -vf"
MESSAGE="Are you sure you want to remove outdated packages? This process can not be undone!"
elif [ "$1" = "help" -o "$1" = "-h" -o "$1" = "--help" ]
then
echo -e "This script checks the packages in your pacman cache directory and removes the packages that are outdated. It doesn't matter if the package is installed or not.\n\n3 arguments can be passed to the script:\n\nlist:\n\tchecks for package that are outdated and prints the names.\n\nclean:\n\tremoves outdated packages.\n\nhelp,-h,--help:\n\tprints this help text.\n\nThis script is written by \"Ali Mousavi\". Please report bugs to [email protected]"
exit 0
else
echo 'Valid Argument are "list", "clean" or "help"'
exit 1
fi
1. `echo -e 'foo\nbar\nbaz'` gets long and unreadable quickly. Instead, use here documents:
cat <<EOF
What should I do?
Valid Argument are "list", "clean" or "help"
EOF
2. Use a case command, looks cleaner:
case "$1" in
list) ... ;;
clean) ... ;;
help|-h|--hep) ... ;;
# Check if the user is sure!
echo "This might take a while based on the amount of cached packages."
echo -n "$MESSAGE(y/n) "
read ANS
if [ $ANS = "y" -o $ANS = "Y" -o $ANS = "yes" ]
then
echo "Processing packages..."
elif [ $ANS = "n" -o $ANS = "N" -o $ANS = "No" ]
then
echo "Exiting on user request"
exit 0
else
echo "Invalid answer"
exit 1
fi
Try:
read -p "hello: " -r
echo $REPLY
And again, `case` should be cleaner in this case.
# Process the packages
cd $DIR #change to cache directory.
pacman -Sl | awk '{ print $2" "$3; }' > $TMPFILE
While you quoted a lot, you left these two out. "$DIR" and "$TMPFILE" should be quoted, otherwise whitespaces will break the code.
for f in $(ls $DIR)
Apart from the same missing quotes, calling `ls` is a waste here. The following is sufficient and (maybe surprisingly) more accurate:
for f in *
How is it more accurate? Run this test script:
#!/bin/bash
DIR=/tmp/foo
mkdir -p "$DIR"
cd "$DIR"
touch a\ b c$'\n'd
for i in *; do
printf '+%s+\n' "$i"
done
printf '%s\n' ---
for i in $(ls $DIR); do
printf '+%s+\n' "$i"
done
Let's not go too far here. Just get the idea.
do
pname=$(file $f | cut -d: -f1) #Produces filename, like: fetchmail-6.3.19-1-i686.pkg.tar.xz"
Calling `file` here is, again, unnecessary. Also, filename of a package can contain ":", e.g., vi-1:050325-1-i686.pkg.tar.xz, which breaks your code.
Don't complicate things:
pname=$f
spname=$(echo $pname | sed 's/-[0-9][0-9]*.*//g') #removes package version: fetchmail
Broken for ntfs-3g-2011.4.12-1-i686.pkg.tar.xz, nvidia-173xx-utils-173.14.31-1-i686.pkg.tar.xz, etc... Something less lousy:
sed 's/\(-[^-]\+\)\{3\}$//' <<< "$pname"
pver=$(echo $pname | sed 's/.*-\([0-9\-\.][0-9\-\.]*-[0-9\-\.][0-9\-\.]*\).*/\1/g') #using pacman -Qi for all files takes a lot of time.
Although this might work for now, this would break if we had an architecture that starts with a digit, e.g. 686. Something less lousy:
sed 's/\(.*\)-\([^-]\+-[^-]\+\)-[^-]\+$/\2/' <<< "$pname"
if [ $(echo $pver | grep '[^0-9\-\.\-\-]' | wc -l) != 0 ] #checks if package version is alright
then
pver=$(pacman -Qpi $f | grep Version | awk '{print $3}')
fi
Again, calling `wc` here is a waste. Anyway, why is this check necessary at all?
newpver=$(grep -e "^$spname " $TMPFILE | awk '{ print $2 }')
if [[ $newpver != $pver ]]
then
$ACTION $f
fi
done
rm -f $TMPFILE
echo "Outdated packages processed successfully!"
exit 0
The post is getting too long, so so much from me. If there's anything you don't understand yet, read bash(1).
If I sound harsh or anything, don't be discouraged. Just keep reading, keep improving.
Last edited by lolilolicon (2011-09-13 12:53:04) -
Bash script to remove hidden files
Hello, I produced this script to clean folders from hidden files
#!/bin/bash
files=$(find . \( -iname '*~' -o -iname '.*' \) -type f)
#count the hidden files
n=$(echo "$files" | wc -l)
if [ $n -eq 0 ]
then
echo "No hidden file found"
exit 0
fi
#prompt to the user the found files
echo "Hidden files found:"
echo "$files"
printf "Remove? [y/N] "
read input
input=$( echo $input | tr '[A-Z]' '[a-z]' )
#take action if confirmed
if [ "$input" == "y" ] || [ "$input" == "yes" ]
then
find . \( -iname '*~' -o -iname '.*' \) -type f -exec rm '{}' \;
echo "Hidden files removed"
else
echo "Nothing was done"
fi
exit 0
As you can see I've not been able to deleting reading from $files, but I have to call a second time the find command. So first improvement is to get rid of it (keeping managing spaces in file names correctly, of course).
Other suggestions are welcomed!falconindy wrote:Or really... just use one of the several well-formed examples in this thread.
Yeah there's one solution using arrays formulated by Trilby, and improved by aesiris. Kind of reminds me of the episode Sheldon Cooper says, "Notify the editors of the Oxford English Dictionary: the word 'plenty' has been redefined to mean 'two'."
As for your earlier post:
falconindy wrote:
No, this simply doesn't work because the entirety of the find result will be quoted as a single filename. You really should just do this all in find...
find . -name '.*' ! -type -d -exec rm -i {} +
The + thing is a good example of saving resources, however the op doesn't want to prompt the user for authorization for every single file (rm -i). Maybe two invocations of find? By the time the user has finished reading the file list, other files may have been created and they will be removed without authorization.
falconindy wrote:Manipulating IFS is entirely wrong for the purposes of reading a list out of a simple string variable (which is wrong on its own -- this is why arrays exist).
I believe that calling a functioning, standards-compliant solution "entirely wrong" means to call it "not as clean as you would desire". So, back to the drawing board:
files=$(find . -type f)
echo "$files"|xargs -d$'\n' rm
Although my earlier post proved one can work with IFS, you were right after all, it is not necessary. Hope you don't spot any further problems or my code will end up being a single word! -
Bash scripting, check filetype with file command
Hi community,
I've got as homework to write a script which uses the command file to check if a file is really a text file, and if yes echo its name.
I wrote the following
#!/bin/bash
for filetype in *
do
a= file $filetype | cut -f2 -d' '
b="ASCII"
if [ "$a"="$b" ]
then
echo "$filetype"
fi
done
however, this does not work.
It just echoes the filetype and all the filenames.
directory
Desktop
Bourne-Again
existe
gzip
kernel26-one-2.6.27-3-i686.pkg.tar.gz
Bourne-Again
list
Bourne-Again
pidof
empty
ps
Bourne-Again
realjpg
Bourne-Again
taille
ASCII
temp.txt
directory
themes
Any ideas?
Why is the filetype echoed, when I declare it as a variable?
Why does the condition thing not work?
Basically, what am I missing?thanks for the ressource.
here's the link
http://tldp.org/LDP/abs/html/
Thanks also for the answers, they were really helpful.
ok, I wanted to post another problem I had but while I was pasting my code in here I realised my mistake. -
[solved] Help with simple bash script
#!/bin/bash
current_state=cat /home/phil/.screen_state
if ["$current_state" = "laptop"];
then
disper -S
echo TV > .screen_state
else
disper -s
echo laptop > .screen_state
fi
[phil@pwned ~]$ ./screenswitch.sh
./screenswitch.sh: line 3: /home/phil/.screen_state: Permission denied
./screenswitch.sh: line 5: [: missing `]'
[phil@pwned ~]$ cat /home/phil/.screen_state
laptop
[phil@pwned ~]$
I'm not sure why I'm getting the permission denied, and also I can't see whats wrong with line 5.
Last edited by Dethredic (2011-08-21 19:46:57)IIRC you need spaces
if [ "foo" = "foo" ]; then
between '[' and another character.
Edit: Got it.
current_state=cat /home/phil/.screen_state
This is plain wrong. I get 'Permission denied' too.
Try
current_state=$(cat /home/phil/.screen_state)
Last edited by karol (2011-08-21 17:59:16) -
Trying to write a simple apple script to reveal a file.
This is what I have now:
tell application "Finder" to reveal POSIX path of "/Users/lloyd/Desktop/my file.txt"
but I get this error:
error "Finder got an error: Can’t make \"/Users/lloyd/Desktop/my file.txt\" into type item." number -1700 from "/Users/lloyd/Desktop/my file.txt" to item
Any help is much appreciatedThanks for the quick answer. Tried changing to file but am now getting this error:
error "Can’t get POSIX file of \"/Users/lloyd/Desktop/my file.txt\"." number -1728 from POSIX file of "/Users/lloyd/Desktop/my file.txt"
btw, I meant to type reveal instead of open but don't think that should be a problem right? The file exists on the desktop, does the space in the file name create a problem? -
Hi I am looking to know what are the mandatory mapping files & Lookup files that required to be mapped for OBIA Financial Analytics for Oracle EBS R12.1.3 source system while implementing OBIA
Is their any document that list outs the need/importance about these files while configuring the same
Thanks & Regards,
VJHi gurus,
any body have an idea how to reconcile the OBIA 7.9.6.2 mapping files and Lookup files data are in line to Source Oracle EBS R12.1.3 system.
Regards,
VJ
Maybe you are looking for
-
Error: The plugin -65221 does not exist in the CMS
Hi, I uploaded my Crystal Reports in the Business Objects InfoView. I can schedule them using the Schedule link but when I use the Reschedule link in the History and click on the paramater value, I' getting the following error: An error has occurred:
-
6/4/2014 - Beta - Flash Player 14.0.0.126
The latest Flash Player 14 builds are now available. You can download Flash Player here:http://www.adobe.com/go/flashplayerbeta. Please note that this build is identical (except for version number) with the official release slated for next week. Pl
-
I was trying to drag-and-drop the contents (most of them are downloaded torrent movies) of my Mac-OS formatted portable hard drive to my Windows-formatted portable hard drive. It didn't work. How do I go about this?
-
Grant the Essbase application permission to user in Shared Services
Hi, We got a problem in granting the Essbase permission to user using Shared Services. We are using Hyperion 9.3.1. (1) We created an Essbase application + database through Essbase Administration Console, say TBC.Sales. (2) Provision the Essbase "Ser
-
Linear List or tree structure?
I am quite new to Java and am studying various data structures. What are the adavanatages over using the binary search tree to a standard linear list? Many Thanks Alan