Home Page for CommandPrograms.com

Terms and Conditions: All content of this site is for instructional purposes only and can be used ONLY AT YOUR OWN RISK - Notice given.

 

Scripts     -- shell scripts examples page

gxmessage multiline example

$ echo -e "Hello.\nHow are you?" |gxmessage -title 'A message for you.' -center -fg Red -bg lightblue -fn 20 -timeout 2 -file -


Linux bash terminal script for closing a process

su to root, save as Close in your /usr/local/bin, #chmod +x /usr/local/bin/Close :
Don't forget to check your path to verify that /usr/local/bin is in your path... $ echo $PATH
If not, save the file in a path sub-directory, but first check for prior use of Close (or whatever
other name you choose) by typing Close and noting the response of 'bash: Close: command not found'.
I use capitalized commands for my own scripts to differentiate them from built-in commands and scripts.

#!/bin/bash
# Close

nam=$1

if [ -z $nam ]; then
printf "%s\n" "USAGE: $(basename $0) [ <process name> or <process number> ]" ;
exit 1 ;
fi

printf "%s\n" "you entered: $nam"

# both of the following lines work, the first accepts PID's
numbers=$(ps -e --sort -pid | grep $nam | cut -b 1-5 ) ;
#numbers=$(pgrep $nam) ;

if [ -z "$numbers" ]; then
printf "%s\n" "process not found ..." ;
exit 1 ;
fi

printf "%s" "numbers:"
printf "%s " $numbers
printf "\n"

number=$(echo $numbers | cut -b 1-5) ;
name=$(ps -e --sort -pid | grep $number | cut -b 25- ) ;
num=$number ;

if [ -n $num ]; then
printf "%s\n" "found a process $name numbered: $num"
fi

num=$(echo $num | cut -b 1-5)
printf "%s" "$num $name is to be closed (Y/N): "

read Go

if [ 'y' = $Go ] || [ 'Y' = $Go ]; then
printf "%s\n" "OK"
kill $num
else
echo 'ABORT'
fi
#end#

Try this prompt ( nano ~/.bashrc ) :
# PS1='$~...etc' (be sure to comment out the old PS1)
PS1='\[\D{%Y-%m-%d} \t [$(ls -A | wc -l)] [\w]\n\u@\H\$ '
# date time [#files] [directory]
# user@host$
PS1='[\[\D{%Y-%m-%d} \t] [$(ls -A | wc -l)] [\033[01;37m\]\w\[\033[00m\]]\n\u@\H\$ ' # hilights directory

New Tab Button for Firefox 4 - 17 ( how to add ):
1. With TABS SHOWING (use either: Tools | Options | Tabs | 'Always show the tab bar', or if you prefer, CTRL-T will start a tab.
2. Select View | Toolbars | Customize
3. Drag the + at the right side of the screen into the buttons storage window area.  You now have the NEW_TAB button.

 

Batch File for appending TEXT files  (tested in xp)

Name this CopyFile.bat and save (preferably in a sub-directory containing only batch files):

@echo off
set cfdir="%~p1"
CD "%cfdir%"
if exist Copy_Out.txt set fileis=Copy_Out.txt del Copy_Out.txt
:loadcopy
if "%1"=="" goto copyend
echo "%~f1"
echo ********** %~f1 > CopyMark
if not exist CopyTemp copy CopyMark+"%1" Copy_Out.txt  >nul
if exist CopyTemp copy CopyMark+"%1"+CopyTemp Copy_Out.txt  >nul
if errorlevel 1 goto Err
copy Copy_Out.txt CopyTemp  >nul
if errorlevel 1 goto Err
shift
goto loadcopy
:copyend
del CopyTemp  >nul
del CopyMark  >nul
if not "%fileis%"=="" echo Copy_Out.txt file has been re-written.
if "%fileis%"=="" echo Copy_Out.txt file has been created.
set cfdir=
set fileis=
pause
exit
:Err
echo An error in the process has occured.
set cfdir=
set fileis=
pause
exit

Then click Start, Run and type sendto or shell:sendto(one will work)<enter>. Right click on white space and select <create shortcut>.  Point to the CopyFile.bat file (whereyou saved it) and follow the dialog to create the new shortcut.

When you would like to append several text files in a directory,  first set a selection of them, right-click and select Send To and point to CopyFile (the new link you created).

 An output file will be created using the selected files.  The order of the files in the output file is not necessarily the same as shown in the window, however, they will all be appended together.

A binary version (tested in xp):

Name this CopyFilB.bat and save (preferably in a sub-directory containing only batch files):

@echo off
set cfdir="%~p1"
CD "%cfdir%"
if exist Copy_Out.bin set fileis=Copy_Out.bin
:loadcopy
if "%1"=="" goto copyend
echo "%~f1"
if not exist CopyTemp copy /B "%1" Copy_Out.bin  >nul
if exist CopyTemp copy /B "%1"+CopyTemp Copy_Out.bin  >nul
if errorlevel 1 goto Err
copy /B Copy_Out.bin CopyTemp  >nul
if errorlevel 1 goto Err
shift
goto loadcopy
:copyend
del CopyTemp  >nul
if not "%fileis%"=="" echo Copy_Out.bin file has been re-written.
if "%fileis%"=="" echo Copy_Out.bin file has been created.
set cfdir=
set fileis=
pause
exit
:Err
echo An error in the process has occured.
set cfdir=
set fileis=
pause
exit

The following appear to work in w98.  The working directory tracking is not as easy in the 98.
Some recursion is possible.

Text 98 version follows:

@echo off
set goofcounter=0
set gooffile=%1
:TestGoof
if "%goofcounter%" == "3" set goofcounter=4
if "%goofcounter%" == "2" set goofcounter=3
if "%goofcounter%" == "1" set goofcounter=2
if "%goofcounter%" == "0" set goofcounter=1
if "%goofcounter%" == "4" goto Err
set gooffile=%gooffile%.txt
if exist %gooffile% goto TestGoof
:loadcopy
if "%1"=="" goto copyend
echo "%1"
echo ********** %1 > CopyMark
if not exist CopyTemp copy CopyMark+"%1" %gooffile% >nul
if exist CopyTemp copy CopyMark+"%1"+CopyTemp %gooffile%  >nul
if errorlevel 1 goto Err
copy %gooffile% CopyTemp  >nul
if errorlevel 1 goto Err
shift
goto loadcopy
:copyend
del CopyTemp  >nul
del CopyMark  >nul
if exist %gooffile% echo %gooffile% file has been created.
set cfdir=
set fileis=
pause
exit
:Err
echo An error in the process has occured.
set cfdir=
set fileis=
pause
exit

Binary 98 version follows:

@echo off
set goofcounter=0
set gooffile=%1
:TestGoof
if "%goofcounter%" == "3" set goofcounter=4
if "%goofcounter%" == "2" set goofcounter=3
if "%goofcounter%" == "1" set goofcounter=2
if "%goofcounter%" == "0" set goofcounter=1
if "%goofcounter%" == "4" goto Err
set gooffile=%gooffile%.bin
if exist %gooffile% goto TestGoof
:loadcopy
if "%1"=="" goto copyend
echo "%1"
if not exist CopyTemp copy /B "%1" %gooffile% >nul
if exist CopyTemp copy /B "%1"+CopyTemp %gooffile%  >nul
if errorlevel 1 goto Err
copy /B %gooffile% CopyTemp  >nul
if errorlevel 1 goto Err
shift
goto loadcopy
:copyend
del CopyTemp  >nul
if exist %gooffile% echo %gooffile% file has been created.
set cfdir=
set fileis=
pause
exit
:Err
echo An error in the process has occured.
set cfdir=
set fileis=
pause
exit

Create a  Sendto:Sendto link: 
(1) Find the SendTo folder (sendto or shell:sendto in the run dialog).
(2) Navigate up one folder to the 'PARENT' folder, Right-Click-Create-Shortcut on then SendTo folder.
(3) Drag and drop the new shortcut into the SendTo folder.
* You should now have a SendTo option: SendTo, which you can send new shortcut copies to. *
 
'This linux command sped up my firefox browser(esp. right-click dialog): # mv /usr/bin/pulseaudio /usr/bin/pulseaudioB'
'If(WHEN) the proffesional web-stirs increase the encryption from 4096 to 65536, we all(ALL) might(WILL!) have to replace our systems.'

Comments or questions: webmaster (at) commandprograms.com  
See captcha? Leave the page. You will find that any site using captcha is wasting your time.

# $ >

© (C) Copyright 2012–2024 by CommandPrograms.com